6

I keep receiving the following error upon running ssh -v -i privatekey [email protected].

OpenSSH_6.9p1, LibreSSL 2.1.8
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 21: Applying options for *
debug1: Connecting to server.org [XXX.XXX.XXX.XXX] port 22.
debug1: Connection established.
debug1: identity file privatekey type 1
debug1: key_load_public: No such file or directory
debug1: identity file privatekey-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.9
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.2p2 Ubuntu-4ubuntu2.1
debug1: match: OpenSSH_7.2p2 Ubuntu-4ubuntu2.1 pat OpenSSH* compat 0x04000000
debug1: Authenticating to server.org:22 as 'user'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client [email protected] <implicit> none
debug1: kex: client->server [email protected] <implicit> none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ssh-rsa SHA256:ig8ZTpASPM0W/drPBHPzcUIr+NtqzOKvVAvihnbaNuc
debug1: Host 'server.org' is known and matches the RSA host key.
debug1: Found key in /Users/XXX/.ssh/known_hosts:3
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: ysm
debug1: Authentications that can continue: publickey
debug1: Offering RSA public key: /Users/XXX/.ssh/id_rsa
debug1: Authentications that can continue: publickey
debug1: No more authentication methods to try.
Permission denied (publickey).

I don't understand what's wrong. I've copied my public key properly and edited permissions on the private key file to ensure it's secure.

2
  • Also, is the -i privatekey the same as the referenced /Users/XXX/.ssh/id_rsa?
    – andol
    Commented Dec 28, 2016 at 9:18
  • debug1: key_load_public: No such file or directory is not an error. Just a debug message. The key is rejected on the server side and without information from the server log, it is not possible to help you.
    – Jakuje
    Commented Dec 28, 2016 at 10:02

2 Answers 2

5

A "Permission denied" error means that the server rejected your connection.

  1. Check logs on the SSH.
  2. How did you transfer the public key to the server? Always use ssh-copy-id to be sure about permissions. Users home directory, the .ssh directory and the authorized_keys file on the server side have strict permission requirements. (see man sshd about authorized_keys).
  3. Check server configuration file /etc/ssh/sshd_config maybe the server is allowed login only to specific users or groups.
1
  • 2
    This worked for me, the user I was trying to log in was missing in /etc/ssh/sshd_config
    – huapito
    Commented May 29, 2018 at 17:13
0

Taking up Slipeer's answer, here is what to add to the /etc/ssh/sshd_config in detail.

In my case, I tried to clone a gitlab project, and the solution should work for any git service. The error was

#15 0.589 debug1: identity file /root/.ssh/id_rsa type -1, 
#15 0.589 debug1: key_load_public: No such file or directory

It disappeared after using

echo "Host *\n  User git\n  HostName gitlab.com\n  AddKeysToAgent yes\n  IdentityFile /root/.ssh/id_rsa" >> /etc/ssh/ssh_config

This is also what is being asked for in your message block:

debug1: Reading configuration data /etc/ssh/ssh_config
...
debug1: key_load_public: No such file or directory

The solution proves that ssh needs to check the server to be a known host. If you have not assigned the needed known host, the gitlab server is not being trusted, which is meant by the key_load_public cannot be found. Yes, the error message is confusing.

You can also manually fill that ssh_config without the echo command, of course.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .