当我使用的密钥显然无法访问时,为什么我仍然可以连接到我的服务器?
从我的电脑连接到服务器:
ssh -l myLogin -i .ssh/key-file <SERVER_IP>
我已经在以下两种配置中尝试过:
- 我的电脑上不存在 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
我刚刚从本地电脑中删除了一个密钥,但它仍然在 ssh 代理的缓存中,并且对服务器仍然有效。注销并再次登录到本地计算机后,一切恢复正常。谢谢@michael-hampton
答案1
您说从本地文件系统中删除的 ssh 密钥仍在使用中,因为您的 ssh 代理已缓存它并在您尝试登录远程主机时提供它。
您可以直接退出本地系统并重新登录,ssh 代理也将重新启动并忘记您的旧密钥。