I am using Ubuntu 18.04 LTS.

  • Whenever, I ssh-copy-id for the first time it puts my username@host at the end of the authorized_keys file line as expected.

On Remote machine:

sacredos@sacredos-DT:~$ cat /home/sacredos/.ssh/auth*
ssh-rsa ... sacredos@sacredos-LT

On Local machine:

sacredos@sacredos-LT:~$ ssh-add -l
4096 SHA256:... sacredos@sacredos-LT (RSA)
  • When, I go to ssh-copy-id to another computer or subsequent ones, it puts the path to the id file there instead.

On Remote machine after clearing and recopying the key over:

sacredos@sacredos-DT:~$ cat /home/sacredos/.ssh/auth*
ssh-rsa ... /home/sacredos/.ssh/id_rsa

On Local machine after copying the key over again:

sacredos@sacredos-LT:~$ ssh-add -l
4096 SHA256:... /home/username/.ssh/id_rsa (RSA)
  • I installed a system fresh to check that is not something I did with configs and such but it behaves the same. It also doesn't matter if it is the same machine in a cleared state or a new machine, if the key is ssh-copy-id'ed over two times or more this happens.

What is going on here?

  • 1
    This is really unclear. Can you give more explicit and reproducible examples of what you expected to see and what you actually saw? – cryptarch Jan 10 at 20:40

From the ssh-copy-id(1) man page:

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 contained 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.

So you should always use eg. -i ~/.ssh/id_rsa.pub (as mentioned in the manpage) or dispense with using ssh-agent if you want to preserve the comment from the identity file.

Notice that by default on debian (and probably on ubuntu too) a GUI session is run as a subprocess of ssh-agent (look at /etc/X11/Xsession.d/90x11-common_ssh-agent), so you will be using ssh-agent even if you didn't mean to.

Also, the key will be automatically added to ssh-agent when running ssh (via ssh-copy-id), without having to run ssh-add, if you have the AddKeysToAgent option enabled (see the ssh_config(5) manpage).

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.