为什么 ssh 找不到身份文件而 ssh-copy-id 可以找到?

为什么 ssh 找不到身份文件而 ssh-copy-id 可以找到?

将身份文件重命名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

相关内容