当我使用的密钥明显无法访问时,为什么我仍然可以连接到我的服务器?
从我的 PC 连接到服务器:
ssh -l myLogin -i .ssh/key-file <SERVER_IP>
我已经在这两种配置中尝试过:
- 我的 PC 上不存在 key-file,并且服务器上不存在 key-file.pub
- 我的电脑上不存在 key-file,但 key-file.pub 内容在
.ssh/authorized_keys
服务器上
两次,我都收到以下消息,但我仍然连接到服务器:
Warning: Identity file .ssh/key-file not accessible: No such file or directory.
注意:我已经正确使用同一台 PC 连接到同一台服务器,使用我在本地删除的另一个正确密钥
我的服务器上是否有错误的配置允许未经适当身份验证的连接?或者我的电脑上是否有任何类型的缓存可以记住如何访问服务器?
SSH 详细
在详细模式下(添加 时-v
),SSH 提供更多信息:
Warning: Identity file .ssh/key-file not accessible: No such file or directory.
...
debug1: Will attempt key: localLogin@localLogin-laptop-ubuntu RSA SHA256:0DH/97OKekTIjdeuc2jO2Ixig9VVTpB7morVj2/GVJw agent
debug1: Will attempt key: localLogin@localLogin-laptop-ubuntu RSA SHA256:6l0joGtcoJv2yvia82zAtXK8PqBLQkesOOwDaCutc20 agent
debug1: Will attempt key: /home/localLogin/.ssh/id_rsa
debug1: Will attempt key: /home/localLogin/.ssh/id_dsa
debug1: Will attempt key: /home/localLogin/.ssh/id_ecdsa
debug1: Will attempt key: /home/localLogin/.ssh/id_ecdsa_sk
debug1: Will attempt key: /home/localLogin/.ssh/id_ed25519
debug1: Will attempt key: /home/localLogin/.ssh/id_ed25519_sk
debug1: Will attempt key: /home/localLogin/.ssh/id_xmss
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]>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Offering public key: localLogin@localLogin-laptop-ubuntu RSA SHA256:0DH/97OKekTIjdeuc2jO2Ixig9VVTpB7morVj2/GVJw agent
debug1: Server accepts key: localLogin@localLogin-laptop-ubuntu RSA SHA256:0DH/97OKekTIjdeuc2jO2Ixig9VVTpB7morVj2/GVJw agent
debug1: Authentication succeeded (publickey).
Authenticated to <SERVER_IP> ([<SERVER_IP>]:22).
...
正如我们所看到的,其中Offering public key
提到了我刚刚从本地 PC 中删除的密钥,但它仍在 ssh 代理的缓存中,并且对服务器仍然有效。注销并再次登录到我的本地计算机后,一切恢复正常。谢谢@michael-hampton
您说您从本地文件系统中删除的 ssh 密钥仍在使用中,因为您的 ssh 代理已缓存它并在您尝试登录远程主机时提供它。
您只需退出本地系统并重新登录,ssh 代理也会重新启动并忘记您的旧密钥。