每次我通过 SSH 连接时,代理都会尝试不存在的密钥:
debug1: Will attempt key: /Users/user/.ssh/id_rsa
debug1: Will attempt key: /Users/user/.ssh/id_dsa
debug1: Will attempt key: /Users/user/.ssh/id_ecdsa
debug1: Will attempt key: /Users/user/.ssh/id_ecdsa_sk
debug1: Will attempt key: /Users/user/.ssh/id_ed25519
debug1: Will attempt key: /Users/user/.ssh/id_ed25519_sk
debug1: Will attempt key: /Users/user/.ssh/id_xmss
...
debug1: Trying private key: /Users/user/.ssh/id_dsa
debug3: no such identity: /Users/user/.ssh/id_dsa: No such file or directory
debug1: Trying private key: /Users/user/.ssh/id_ecdsa
debug3: no such identity: /Users/user/.ssh/id_ecdsa: No such file or directory
debug1: Trying private key: /Users/user/.ssh/id_ecdsa_sk
debug3: no such identity: /Users//.ssh/id_ecdsa_sk: No such file or directory
debug1: Trying private key: /Users/user/.ssh/id_ed25519
debug3: no such identity: /Users/user/.ssh/id_ed25519: No such file or directory
debug1: Trying private key: /Users/user/.ssh/id_ed25519_sk
debug3: no such identity: /Users/user/.ssh/id_ed25519_sk: No such file or directory
debug1: Trying private key: /Users/user/.ssh/id_xmss
debug3: no such identity: /Users/user/.ssh/id_xmss: No such file or directory
只有 id_rsa 存在,其余的已被删除。我甚至根本不记得其中一些。在我的 ~/.ssh 文件夹中,我只有:
╰─➤ $ ls -a /Users/user/.ssh
. authorized_keys id_ed25519_qemu.pub known_hosts.old
.. config id_rsa
.DS_Store config.backup id_rsa.pub
.id_rsa.pub.swp id_ed25519_qemu known_hosts
如您所见,代理甚至无法使用 qemu 密钥。输入ssh-add -D
输出All identities removed
,但密钥还是被尝试了。并且ssh-add -L
只给了我The agent has no identities.
我在 Keychain Access 上通过搜索 SSH 进行检查的结果,并且只有id_rsa
和三个其他 .pem 密钥保存在其他地方的文件夹中。
我如何删除不存在的密钥?
答案1
这些不是旧密钥。这只是系统自动查找不同密钥类型的设置,以防您碰巧生成不同类型的密钥。例如,也许您主要使用 RSA 密钥,然后在某个时候您决定更喜欢椭圆曲线密钥,因此您生成了一个 EC 密钥。使用这样的系统设置,您无需修改 SSH 配置即可开始使用新的 EC 密钥,只需生成一个具有该密钥类型的默认文件名的密钥,它就可以正常工作。