Usually in the past I've always manually copied over my SSH public key to the remotes where necessary. I'm on a Mac and I finally decided to start using ssh-copy-id to make my life simpler, so I just used homebrew to install it.

I just used ssh-copy-id for the first time and am little confused by the result.

On my local machine, when viewing my id_rsa.pub key, it ends with username@machinename. I love this and it's made it easy to identify keys I can delete on remote machines later on.

I just used ssh-copy-id on my local machine to move my public key to a remote and then took a look at the authorized_keys file on the remote. I noticed that on the remote instead of my public key ending with myusername@mymachinename (as expected) it now ends with /Users/myusername/.ssh/id_rsa ??

Why the discrepancy? Is there any way to force ssh-copy-id to use username@machinename like it does on my local machine?

This might just be a misunderstanding I have with SSH and keys in general, but any thoughts are appreciated?


Just discovered that this only happens when I exclude my identity file and assume defaults.

Basically if I only do: ssh-copy-id user@hostname then I get this awkward comment in the authorized_keys file on the remote.

If I specify my public key: ssh-copy-id -i ~/.ssh/id_rsa.pub user@hostname then everything copies over as expected, using myusername@machinename as expected ?!

What's causing this oddity? The following link says that it should always default to using my id_rsa.pub file anyway, so I shouldn't need to specify it to get the right comment on the remote should I? http://linux.die.net/man/1/ssh-copy-id

1 Answer 1


Add option -i when running ssh-copy-id. This is explained in the manual:

 Default behaviour without -i, is to check if 'ssh-add -L' provides any
 output, and if so those keys are used.  Note that this results in the
 comment on the key being the filename that was given to ssh-add(1) when
 the key was loaded into your ssh-agent(1) rather than the comment con-
 tained in that file, which is a bit of a shame.  Otherwise, if ssh-add(1)
 provides no keys contents of the default_ID_file will be used.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.