![为什么 ssh 找不到身份文件而 ssh-copy-id 可以找到?](https://linux22.com/image/740930/%E4%B8%BA%E4%BB%80%E4%B9%88%20ssh%20%E6%89%BE%E4%B8%8D%E5%88%B0%E8%BA%AB%E4%BB%BD%E6%96%87%E4%BB%B6%E8%80%8C%20ssh-copy-id%20%E5%8F%AF%E4%BB%A5%E6%89%BE%E5%88%B0%EF%BC%9F.png)
将身份文件重命名id_ed2519_2(.pub)
为后id_ed2519(.pub)
,
ssh-copy-id
可以使用文件连接到远程服务器id_ed25519
(它要求输入密码),但ssh
不能,除非我添加身份文件选项(它要求输入密码):
$ ssh-copy-id -n remoteserver
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
Enter passphrase for key '/home/helloworld/.ssh/id_ed25519':
/usr/bin/ssh-copy-id: WARNING: All keys were skipped because they already exist on the remote system.
$ ssh remoteserver
no such identity: /home/helloworld/.ssh/id_ed25519_2: No such file or directory
Permission denied (publickey).
$ ssh remoteserver -i ./ssh/id_ed25519
Enter passphrase for key 'id_ed25519':
怎么可能ssh-copy-id
在没有 IdentityFile 选项的情况下找到身份文件 id_ed25519,同时ssh
继续询问不存在的文件 id_ed25519_2(甚至在重新启动服务器和客户端之后)?
显然,一定有一些配置文件告诉 ssh 寻找 id_ed25519_2。它不在 中authorized_keys
。
答案1
ssh-copy-id 是一个辅助脚本,除非另有限制(使用选项-i <identity_file>
),否则会主动查找所有~/.ssh/*.pub
公钥文件。
另一方面,如果没有类似的-i <identity_file>
选项,则只会查找默认的、和文件。如果 ssh 查找其他文件,那是因为它被配置为在例如文件中执行此操作 。ssh
~/.ssh/id_dsa
~/.ssh/id_ecdsa
~/.ssh/id_ed25519
~/.ssh/id_rsa
~/.ssh/config