Unix & Linux
linux ssh macintosh ssh-keygen
Updated Sun, 04 Sep 2022 08:36:49 GMT

ssh public key not getting copied over


I created a public/private key pair using the ssh-keygen -t rsa in my ~/.ssh folder.

I then copied the key over using the ssh-copy-id username@remoteserver.com command and received this notification.

Number of key(s) added:        2

I tried logging in but was still prompted for a password. I ran a find / -name id_rsa.pub command and searched my remote server's .ssh folder but couldn't find the master key anywhere. I tried chmod with both go-rwx and 777 permissions on the pub key but to no avail. Why is the file not getting copied, yet I receive no error messages?

EDIT: I added the -v tag to the ssh command and got this output

OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: Connecting to [servername] [ipaddress] port 22.
debug1: Connection established.
debug1: identity file /Users/william.roberts/.ssh/id_rsa type 1
debug1: identity file /Users/william.roberts/.ssh/id_rsa-cert type -1
debug1: identity file /Users/william.roberts/.ssh/id_dsa type -1
debug1: identity file /Users/william.roberts/.ssh/id_dsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.2
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.3
debug1: match: OpenSSH_5.3 pat OpenSSH_5*
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Server host key: RSA 7c:3a:61:86:ec:53:40:c3:b0:5e:c2:9f:f4:bf:35:64
debug1: Host '[servername]' is known and matches the RSA host key.
debug1: Found key in /Users/william.roberts/.ssh/known_hosts:7
debug1: ssh_rsa_verify: signature correct
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,gssapi-keyex,gssapi-with-mic,password
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /Users/william.roberts/.ssh/id_rsa
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Offering RSA public key: /Users/william.roberts/.ssh/other_rsa
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Offering RSA public key: /Users/william.roberts/.ssh/id_rsa
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Trying private key: /Users/william.roberts/.ssh/id_dsa
debug1: Next authentication method: password

Edit 2:

output of ls -la .ssh

drwxrwxrwx  2 root root 4096 Dec 10 19:15 .
dr-xr-x---. 5 root root 4096 Nov 19 22:44 ..
-rw-------  1 root root 3019 Dec 10 19:51 authorized_keys
-rw-r--r--  1 root root  427 Nov 24 19:40 known_hosts



Solution

Your .ssh directory can't be world accessible:

chmod 700 ~/.ssh

should fix it