SSH – Why SSH Doesn’t Find Identity File While SSH-Copy-ID Does?

ssh

After renaming identity files id_ed2519_2(.pub) to id_ed2519(.pub),
ssh-copy-id can connect to remoteserver using file id_ed25519 (it asks for passphrase), while ssh can't, unless I add an identity file option (it asks for passphrase) :

$ 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': 

How is that possible that ssh-copy-id happens to find the identity files id_ed25519 without IdentityFile option, while ssh continues to ask for non existing file id_ed25519_2 (even after rebooting server and client) ?

Obviously there must be some configuration file saying to ssh to look for id_ed25519_2. It is not in authorized_keys.

Best Answer

ssh-copy-id is a helper script, that unless otherwise restricted (with the -i <identity_file> option), actively looks for all ~/.ssh/*.pub public key files.

Without a similar -i <identity_file> option ssh on the other hand only looks for the default ~/.ssh/id_dsa, ~/.ssh/id_ecdsa, ~/.ssh/id_ed25519 and ~/.ssh/id_rsa files.
If ssh looks for other files, that is because it is configured to do so in for instance a ~/.ssh/config file.

Related Topic