0

I generated a ssh key pair with ssh-keygen, use ssh-copy-id to the server and checked that the public key was added to authorized_keys, but then when i try to connect with ssh -i ~/.ssh/MY_KEY user@server it is still asking me for the password. I don't have root privileges in the server but my .ssh directory only has "authorized_keys" and "known_hosts" files, both have the public key "MY_KEY". I already checked every permission on /User, /.ssh and both files inside /.ssh but i don't have access to sshd_config

This is what i get when trying to connect with

ssh -v -i ~/.ssh/MY_KEY user@serverIP
debug1: Reading configuration data /Users/user/.ssh/config
debug1: /Users/user/.ssh/config line 18: Applying options for *
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 48: Applying options for *
debug1: Connecting to serverIP [serverIP] port 22.
debug1: Connection established.
debug1: identity file /Users/user/.ssh/MY_KEY type 0
debug1: identity file /Users/user/.ssh/MY_KEY-cert type -1
debug1: identity file /Users/user/.ssh/gitlabkey type 3
debug1: identity file /Users/user/.ssh/gitlabkey-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_7.9
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.4
debug1: match: OpenSSH_7.4 pat OpenSSH_7.0*,OpenSSH_7.1*,OpenSSH_7.2*,OpenSSH_7.3*,OpenSSH_7.4*,OpenSSH_7.5*,OpenSSH_7.6*,OpenSSH_7.7* compat 0x04000002
debug1: Authenticating to serverIP:22 as 'user'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256@libssh.org
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: chacha20-poly1455@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1455@openssh.com MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:oF1yjVJjhgf9N7u84hk8QqZrY
debug1: Host 'serverIP' is known and matches the ECDSA host key.
debug1: Found key in /Users/user/.ssh/known_hosts:17
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 134217728 blocks
debug1: Will attempt key: /Users/user/.ssh/MY_KEY RSA SHA256:W3JxHToIyelBpl4 explicit
debug1: Will attempt key: /Users/user/.ssh/gitlabkey ED25519 SHA256:KAd+YwkK6dWptbtLvWg explicit
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<rsa-sha2-256,rsa-sha2-512>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Offering public key: /Users/user/.ssh/MY_KEY RSA SHA256:W3JxHToIyelB6Upl4 explicit
debug1: Authentications that can continue: publickey,password
debug1: Offering public key: /Users/user/.ssh/gitlabkey ED25519 SHA256:KAd+YwkK6dWtvWg explicit
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: password
user@serverIP's password:

I honestly don't know what else to try. I don't get why is it trying the correct key (MY_KEY) but it clearly fails.

  • I don't see any indication in the logs that MY_KEY is being used. Or is the actual key name 'staging_rsa' ? It's important that you reflect commands exactly if you want help debugging them. – Daniel Farrell Oct 3 '19 at 18:56
  • Yes, the actual key name is staging_rsa, sorry, i edited the 1st post now – Joaco Piersigilli Oct 3 '19 at 19:03
  • debug1: Offering public key: /Users/user/.ssh/staging_rsa RSA SHA256:W3JxHToIyelB6Upl4 explicit that key is getting offered, so the remote side is rejecting it. Could be that the remote side disallows pubkey auth, or tht permissions are wrong on the remote .ssh though granted you've checked that. – Daniel Farrell Oct 3 '19 at 19:05
  • 2
    check what the logs say on the server – ilkkachu Oct 3 '19 at 19:07
  • @DanielFarrell i know, if the remote side disallows pubkey auth i dont know how to see that. – Joaco Piersigilli Oct 3 '19 at 19:11
0

For anyone having the same problem... after a long time i could resolve it.

I was tired of trying things so i deleted both authorized_keys and known_hosts, all i had was the empty .ssh directory. At that moment i got disconnected from the server and thought i broke it all, but since i'm in a mac, by doing this https://coderwall.com/p/8ag5aq/ssh-broken-pipe-fix-mac-os-x i could connect again.

I simply execute again the ssh-copy-id command from the mac and it automatically created, on the server, the file "authorized_keys" but not "known_hosts".

Just with that i then run ssh -i /path/to/MYKEY user@serverIP and it worked like a charm without prompting for password.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.