ssh-copy-id 之后服务器仍然要求输入密码

ssh-copy-id 之后服务器仍然要求输入密码

我使用 ssh-copy-id 将 SSH 公钥复制到服务器,但服务器仍然要求输入密码。我检查了 ssh 文件夹中文件的权限,它们仅供用户读取。我还检查了 sshd_config 文件,PasswordAuthentication 行以 yes 结尾。我检查了服务器上的authorized_keys 文件,该密钥与我在 id_rsa.pub 中的密钥匹配。

我跑

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

这是我得到的错误的一部分(StackExchange 不允许我添加所有错误)-

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

谢谢。

答案1

您确定使用正确的密钥文件规范吗?将您的上述调试日志与我的进行比较:

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).

您会看到提供的公钥指定了完整路径(它是在其中创建并实际驻留的),而不是您的只是一个文件名。也许检查一下你的本地配置(关键字IdentityFile:)?

相关内容