我通常使用特米乌斯从 Mac 到 SSH 我的 Debian 服务器,到目前为止效果很好。现在只是出于好奇,我尝试使用内置的 Mac SSH 客户端,不涉及第三方。
这是内容〜/ .ssh /配置在我的 Mac 上:
Host stalingrad
Hostname xxx.xxx.xxx.xxx
User root
Port 22
IdentityFile ~/.ssh/digital_ocean_id_rsa.pub
IdentitiesOnly yes
我检查过我的 Mac〜/.ssh/digital_ocean_id_rsa.pub与我的 Debian 盒子相匹配/root/.ssh/authorized_keys
同样在 VPS 上运行以下命令:
$ chmod 700 /root/.ssh
$ chmod 600 /root/.ssh/authorized_keys
$ /etc/init.d/ssh restart
好的,让我们尝试一下 ssh:
ssh [email protected]
我得到了这些:
debug1: Will attempt key: /Users/andre/.ssh/id_rsa RSA SHA256:xxxxxxxxxxxxxxxx
debug1: Will attempt key: /Users/andre/.ssh/id_ecdsa
debug1: Will attempt key: /Users/andre/.ssh/id_ecdsa_sk
debug1: Will attempt key: /Users/andre/.ssh/id_ed25519
debug1: Will attempt key: /Users/andre/.ssh/id_ed25519_sk
debug1: Will attempt key: /Users/andre/.ssh/id_xmss
debug1: Will attempt key: /Users/andre/.ssh/id_dsa
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,[email protected],ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,[email protected],[email protected]>
debug1: kex_input_ext_info: [email protected]=<0>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering public key: /Users/andre/.ssh/id_rsa RSA SHA256:xxxxxxxxxxxxxxxx
debug1: Authentications that can continue: publickey
debug1: Trying private key: /Users/andre/.ssh/id_ecdsa
debug1: Trying private key: /Users/andre/.ssh/id_ecdsa_sk
debug1: Trying private key: /Users/andre/.ssh/id_ed25519
debug1: Trying private key: /Users/andre/.ssh/id_ed25519_sk
debug1: Trying private key: /Users/andre/.ssh/id_xmss
debug1: Trying private key: /Users/andre/.ssh/id_dsa
debug1: No more authentication methods to try.
[email protected]: Permission denied (publickey).
这就是内容/var/log/auth.log在 VPS 上:
Oct 31 14:58:29 stalingrad sshd[249851]: error: kex_exchange_identification: Connection closed by remote host
Oct 31 14:58:29 stalingrad sshd[249851]: Connection closed by xxx.xxx.xxx.xxx port 52960
Oct 31 14:58:50 stalingrad sshd[253607]: Connection closed by authenticating user root yyy.yyy.yyy.yyy port 60773 [preauth]
Oct 31 14:58:59 stalingrad sshd[254173]: error: kex_exchange_identification: Connection closed by remote host
Oct 31 14:58:59 stalingrad sshd[254173]: Connection closed by xxx.xxx.xxx.xxx port 57792
Oct 31 14:59:27 stalingrad sshd[254174]: Received disconnect from yyy.yyy.yyy.yyy port 60774:11: Normal Shutdown [preauth]
Oct 31 14:59:27 stalingrad sshd[254174]: Disconnected from authenticating user root yyy.yyy.yyy.yyy port 60774 [preauth]
Oct 31 14:59:29 stalingrad sshd[254176]: error: kex_exchange_identification: Connection closed by remote host
Oct 31 14:59:29 stalingrad sshd[254176]: Connection closed by xxx.xxx.xxx.xxx port 34386
Oct 31 14:59:49 stalingrad sshd[254177]: Connection closed by authenticating user root yyy.yyy.yyy.yyy port 60777 [preauth]
Oct 31 14:59:59 stalingrad sshd[254180]: error: kex_exchange_identification: Connection closed by remote host
Oct 31 14:59:59 stalingrad sshd[254180]: Connection closed by xxx.xxx.xxx.xxx port 39216
好像ssh没有读取指定的私钥文件,也就是数字_海洋_id_rsa。相反,它尝试读取一堆名称以“id_”开头的私钥文件。这是怎么回事?
答案1
我不知道有任何 ssh 使用公钥作为 IdentityFile
确保您使用私钥文件名而不是公钥文件名。
Host stalingrad
Hostname xxx.xxx.xxx.xxx
User root
Port 22
IdentityFile ~/.ssh/digital_ocean_id_rsa
IdentitiesOnly yes