0

I copied my SSH public key to a server using ssh-copy-id, but the server still ask for a password. I checked the permission on the files in the ssh folder and they are readable for user only. I also checked the sshd_config file and the PasswordAuthentication line ends with yes. I checked the authorized_keys file on the server and the key matches the key I have in my id_rsa.pub.

I run

ssh -i <path_to_key> <myusername@host> -vvv

and this is part of the error I got (StackExchange won't let me add all of it) -

OpenSSH_7.4p1, OpenSSL 1.0.2k-fips  26 Jan 2017
.....
debug1: Connecting to <host> port 22.
debug1: Connection established.
debug1: identity file id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file id_rsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.4
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.4
debug1: match: OpenSSH_7.4 pat OpenSSH* compat 0x04000000
debug2: fd 3 setting O_NONBLOCK
debug1: Authenticating to <host>:22 as <myusername>
debug3: hostkeys_foreach: reading file "/users/studs/bsc/2016/orelhaz/.ssh/known_hosts"
debug3: record_hostkey: found key type ECDSA in file /users/studs/bsc/2016/orelhaz/.ssh/known_hosts:119
debug3: load_hostkeys: loaded 1 keys from <host>
debug3: order_hostkeyalgs: prefer hostkeyalgs: [email protected],[email protected],[email protected],ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521
.......
debug3: hostkeys_foreach: reading file "/users/studs/bsc/2016/orelhaz/.ssh/known_hosts"
debug3: record_hostkey: found key type ECDSA in file /users/studs/bsc/2016/orelhaz/.ssh/known_hosts:119
debug3: load_hostkeys: loaded 1 keys from <host>
debug3: hostkeys_foreach: reading file "/users/studs/bsc/2016/orelhaz/.ssh/known_hosts"
debug3: record_hostkey: found key type ECDSA in file /users/studs/bsc/2016/orelhaz/.ssh/known_hosts:119
debug3: load_hostkeys: loaded 1 keys from 132.72.44.112
debug1: Host <host> is known and matches the ECDSA host key.
debug1: Found key in /users/studs/bsc/2016/orelhaz/.ssh/known_hosts:119
debug3: send packet: type 21
debug2: set_newkeys: mode 1
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug3: receive packet: type 21
......
debug3: start over, passed a different list publickey,gssapi-keyex,gssapi-with-mic,password
debug3: preferred gssapi-keyex,gssapi-with-mic,publickey,keyboard-interactive,password
debug3: authmethod_lookup gssapi-keyex
debug3: remaining preferred: gssapi-with-mic,publickey,keyboard-interactive,password
debug3: authmethod_is_enabled gssapi-keyex
debug1: Next authentication method: gssapi-keyex
debug1: No valid Key exchange context
debug2: we did not send a packet, disable method
...........
No Kerberos credentials available (default cache: KEYRING:persistent:8108)

debug1: Unspecified GSS failure.  Minor code may provide more information
No Kerberos credentials available (default cache: KEYRING:persistent:8108)

debug2: we did not send a packet, disable method
debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive,password
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: id_rsa
debug3: send_pubkey_test
debug3: send packet: type 50
debug2: we sent a publickey packet, wait for reply
debug3: receive packet: type 51
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug2: we did not send a packet, disable method
debug3: authmethod_lookup password
debug3: remaining preferred: ,password
debug3: authmethod_is_enabled password
debug1: Next authentication method: password

Thanks.

7
  • Add the output of ssh username@machine to the question. Also, does the config on the machine have PubkeyAuthentication yes? May 28, 2022 at 15:20
  • when I run ssh username@machine it's just ask for my password. I opened the ssh_config file on the remote machine but it only have - "GSSAPIAuthentication yes".
    – omerk
    May 28, 2022 at 16:56
  • not the same thing! May 28, 2022 at 17:14
  • According to the debug output, ssh offered the id_rsa key to the server and the server didn't accept it. If you check the syslogs on the remote server, you might find that the sshd process logged the reason why it didn't accept the key.
    – Kenster
    May 28, 2022 at 17:55
  • Does the config file actually have PubkeyAuthentication yes? If so, are you sure that ssh-copy-id actually worked? May 28, 2022 at 19:23

1 Answer 1

0

Sure you are using the correct key file specification? Compare your above debug log to mine:

debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive,password
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Offering public key: /home/user/.ssh/id_rsa RSA SHA256:6wZNjCyUdVXcrf05PJaayPZ0iB/0052zDvA+luvO0JM
debug3: send packet: type 50
debug2: we sent a publickey packet, wait for reply
debug3: receive packet: type 60
debug1: Server accepts key: /home/user/.ssh/id_rsa RSA SHA256:6wZNjCyUdVXcrf05PJaayPZ0iB/0052zDvA+luvO0JM
debug3: sign_and_send_pubkey: RSA SHA256:6wZNjCyUdVXcrf05PJaayPZ0iB/0052zDvA+luvO0JM
debug3: sign_and_send_pubkey: signing using ssh-rsa SHA256:6wZNjCyUdVXcrf05PJaayPZ0iB/0052zDvA+luvO0JM
debug3: send packet: type 50
debug3: receive packet: type 52
debug1: Authentication succeeded (publickey).

You see that the public key offered has a full path (the one it was created in and actually resides) specified, as opposed to your's which is just a filename. Mayhap check your local config (keyword: IdentityFile)?

1
  • I tried with the full path but I still get the same problem. But thanks anyway
    – omerk
    May 29, 2022 at 10:53

You must log in to answer this question.

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