我认为这从来没能正常工作过。我记不清了,只是一直在输入密码。我管理十台负载平衡服务器,但我通过内部 IP 在内部访问它们。当我通过 ssh-copy-id 将密钥复制到远程系统时,它看起来成功验证了身份,但仍然提示我输入密码。我的 .ssh 文件夹的权限为 600,只有 known_hosts 的权限为 644,密钥工作的其他服务器的权限相同。/var/log/secure 表示它已被接受。/etc/ssh/* 中的所有权限都是 644。有什么想法吗?提前谢谢您!
**/var/log/secure**
Jul 25 07:30:55 X sshd[25970]: Accepted password for user from 172.29.2.133 port 23423 ssh2
Jul 25 07:30:55 X sshd[25970]: pam_unix(sshd:session): session opened for user user by (uid=0)
Jul 25 07:37:27 X sudo: pam_unix(sudo:auth): conversation failed
Jul 25 07:37:27 X sudo: pam_unix(sudo:auth): auth could not identify password for [user]
Jul 25 07:38:15 X sudo: user: TTY=pts/1 ; PWD=/home/user ; USER=root ; COMMAND=/usr/bin/less /var/log/secure
**ssh -v output**
OpenSSH_6.6.1, OpenSSL 1.0.1f 6 Jan 2014
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 29: Applying options for *
debug1: Connecting to X [172.20.2.131] port 22.
debug1: Connection established.
debug1: identity file /home/user/.ssh/id_rsa type 1
debug1: identity file /home/user/.ssh/id_rsa-cert type -1
debug1: identity file /home/user/.ssh/id_dsa type -1
debug1: identity file /home/user/.ssh/id_dsa-cert type -1
debug1: identity file /home/user/.ssh/id_ecdsa type -1
debug1: identity file /home/user/.ssh/id_ecdsa-cert type -1
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: channel 0: free: client-session, nchannels 1
Connection to X closed.
Transferred: sent 11752, received 9832 bytes, in 262.0 seconds
Bytes per second: sent 44.9, received 37.5
debug1: Exit status 0
user@AUR-000229:/mnt/c/Users/user$ ssh -v X
OpenSSH_6.6.1, OpenSSL 1.0.1f 6 Jan 2014
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 29: Applying options for *
debug1: Connecting to X [172.20.2.131] port 22.
debug1: Connection established.
debug1: identity file /home/user/.ssh/id_rsa type 1
debug1: identity file /home/user/.ssh/id_rsa-cert type -1
debug1: identity file /home/user/.ssh/id_dsa type -1
debug1: identity file /home/user/.ssh/id_dsa-cert type -1
debug1: identity file /home/user/.ssh/id_ecdsa type -1
debug1: identity file /home/user/.ssh/id_ecdsa-cert type -1
debug1: identity file /home/user/.ssh/id_ed25519 type -1
debug1: identity file /home/user/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.8
debug1: Remote protocol version 2.0, remote software version OpenSSH_4.3
debug1: match: OpenSSH_4.3 pat OpenSSH_4* compat 0x00000000
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<3072<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 8a:0f:76:f8:55:e7:65:25:10:ae:f3:d9:3c:dd:48:0a
debug1: Host 'X' is known and matches the RSA host key.
debug1: Found key in /home/user/.ssh/known_hosts:10
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: password
debug1: Next authentication method: password
user@X's password:
debug1: Authentication succeeded (password).
Authenticated to X ([172.20.2.131]:22).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: Sending environment.
debug1: Sending env LANG = en_US.UTF-8
Last login: Tue Jul 25 07:26:18 2017 from 172.29.2.133
**Another server who with the same setup, keys work.**
OpenSSH_6.6.1, OpenSSL 1.0.1f 6 Jan 2014
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 29: Applying options for *
debug1: Connecting to X [172.20.2.132] port 22.
debug1: Connection established.
debug1: identity file /home/user/.ssh/id_rsa type 1
debug1: identity file /home/user/.ssh/id_rsa-cert type -1
debug1: identity file /home/user/.ssh/id_dsa type -1
debug1: identity file /home/user/.ssh/id_dsa-cert type -1
debug1: identity file /home/user/.ssh/id_ecdsa type -1
debug1: identity file /home/user/.ssh/id_ecdsa-cert type -1
debug1: identity file /home/user/.ssh/id_ed25519 type -1
debug1: identity file /home/user/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.8
debug1: Remote protocol version 2.0, remote software version OpenSSH_4.3
debug1: match: OpenSSH_4.3 pat OpenSSH_4* compat 0x00000000
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<3072<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 15:5c:e0:96:15:6c:18:85:e8:e8:86:ab:3a:e7:7e:b7
debug1: Host 'X' is known and matches the RSA host key.
debug1: Found key in /home/user/.ssh/known_hosts:25
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-with-mic,password
debug1: Next authentication method: gssapi-with-mic
debug1: Unspecified GSS failure. Minor code may provide more information
No Kerberos credentials available
debug1: Unspecified GSS failure. Minor code may provide more information
No Kerberos credentials available
debug1: Unspecified GSS failure. Minor code may provide more information
debug1: Unspecified GSS failure. Minor code may provide more information
No Kerberos credentials available
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/user/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 279
debug1: key_parse_private2: missing begin marker
debug1: read PEM private key done: type RSA
debug1: Authentication succeeded (publickey).
Authenticated to X ([172.20.2.132]:22).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: Sending environment.
debug1: Sending env LANG = en_US.UTF-8
Last login: Tue Jul 25 07:27:19 2017 from 172.29.2.133
答案1
并不是要反驳任何人,但是如果服务器仅提示密码验证,则您的客户端将不会提供密钥。
在上面的调试中:
debug1:可以继续的身份验证:密码
debug1:下一个身份验证方法:密码
用户@X 的密码:
debug1:身份验证成功(密码)。
已向 X ([172.20.2.131]:22) 进行身份验证。
您正在连接的服务器不允许您(客户端)提供 PSK。服务器的 sshd_config 必须具有以下内容:
公钥认证 是
授权密钥文件 .ssh/authorized_keys
为了进行比较,这是我的 ssh 调试输出,用于正确接受公钥认证的服务器:
debug1:可以继续的身份验证:publickey,keyboard-interactive
debug1:下一个认证方法:publickey
debug1:提供 RSA 公钥:imported-openssh-key
debug1:服务器接受密钥:pkalg rsa-sha2-512 blen 151
debug1:单线程到多线程 CTR 密码交换 - 客户端请求
debug1:认证成功(公钥)。
-- 抱歉格式不正确 --
答案2
作为达特莫克建议检查服务器上 authorized_keys 文件的所有权,以及本地 id_rsa 文件的所有权。您还应确保只有所有者具有读取权限 ( chmod 400 <file>
)。查看服务器启动时 sshd 的日志输出,如果这些权限有问题,它会发出警告。
您的 ssh 会话的调试日志显示它是不是提供私钥进行身份验证(如问题标题所示),并且从表面上看,您的服务器甚至没有宣传它将接受私钥身份验证。成功的私钥身份验证会话的调试日志应包含以下内容:
debug1: Authentications that can continue: publickey,**others
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/user/.ssh/id_rsa
debug1: Server accepts key: pkalg rsa-sha2-512 blen 407
debug1: Authentication succeeded (publickey).
除非服务器声明Authentications that can continue: publickey
,否则您的客户端永远不会提供。