Ssh – “Permission denied (publickey)” with “key_load_public: No such file or directory” upon SSH attempt

sshssh-keys

I keep receiving the following error upon running ssh -v -i privatekey user@server.org.

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 chacha20-poly1305@openssh.com <implicit> none
debug1: kex: client->server chacha20-poly1305@openssh.com <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.

Best Answer

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.