将身份文件重命名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':
Run Code Online (Sandbox Code Playgroud)
怎么可能ssh-copy-id在没有 IdentityFile 选项的情况下找到身份文件 id_ed25519,同时ssh继续询问不存在的文件 id_ed25519_2(即使在重新启动服务器和客户端之后)?
很明显肯定有配置文件告诉ssh去寻找id_ed25519_2。它不在authorized_keys.
ssh-copy-id 是一个辅助脚本,除非另有限制(使用-i <identity_file>选项),否则会主动查找所有~/.ssh/*.pub 公钥文件。
如果没有类似的-i <identity_file>选项ssh,另一方面只查找默认~/.ssh/id_dsa,~/.ssh/id_ecdsa,~/.ssh/id_ed25519和~/.ssh/id_rsa文件。
如果 ssh 寻找其他文件,那是因为它被配置为在例如一个~/.ssh/config 文件中这样做。