![带有证书的 SSH 连接仍然要求输入密码](https://linux22.com/image/1056954/%E5%B8%A6%E6%9C%89%E8%AF%81%E4%B9%A6%E7%9A%84%20SSH%20%E8%BF%9E%E6%8E%A5%E4%BB%8D%E7%84%B6%E8%A6%81%E6%B1%82%E8%BE%93%E5%85%A5%E5%AF%86%E7%A0%81.png)
以下是来自客户:
ssh -p 2xxx -vvv -i /home/jxxxxx/.ssh/authorized_keys ixxxxx.com
以下是调试信息(-vvv)的相关部分:
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug2: key: /home/jxxxxx/.ssh/authorized_keys (0x7ff95d1456b0), explicit
debug1: Authentications that can continue: publickey,password
debug3: start over, passed a different list publickey,password
debug3: preferred gssapi-keyex,gssapi-with-mic,publickey,keyboard-interactive,password
debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive,password
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Offering DSA public key: /home/jxxxxx/.ssh/authorized_keys
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply
debug1: Authentications that can continue: publickey,password
debug2: we did not send a packet, disable method
debug3: authmethod_lookup password
以下是来自 /var/log/auth.log 的信息服务器:
Aug 9 09:11:00 ixxxxx sshd[8200]: Connection closed by xxx.xxx.xxx.xxx(CLIENT ip) [preauth]
以下是服务器:
/home/jxxxxx 755
/home/jxxxxx/.ssh 700
/home/jxxxxx/.ssh/id_dsa and id_rsa 600
以下是客户:
/home/jxxxxx 755
/home/jxxxxx/.ssh 700
/home/jxxxxx/.ssh/authorized_keys 600 (contains id_dsa.pub and id_rsa.pub)
/etc/ssh/sshd_config 的相关部分(服务器和客户端)
Port 2xxx
Protocol 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key
LoginGraceTime 120
PermitRootLogin no
AllowUsers jxxxxx
StrictModes yes
RSAAuthentication yes
PubkeyAuthentication yes
ChallengeResponseAuthentication no
UsePAM yes
有什么建议吗?这是我在 StackExchange 上的第一个查询,所以这对我来说真是一个难题。关于这个主题的其他 askubuntu 问题/答案都没有起到作用。
答案1
您的私钥必须位于客户相应的公钥必须添加authorized_keys
到服务器。
如果您的私钥名为 或${HOME}/.ssh/id_dsa
,则${HOME}/.ssh/id_rsa
无需选择-i
,ssh
因为它会自动尝试这些默认密钥名称(尽管如果您想明确说明将使用默认私钥,这也不会有什么坏处)。