I'd like to copy a public ssh key from the ~/.ssh/id_rsa.pub
file on my local machine to the ~/.ssh/authorized_keys
file on a remote host that is two ssh hops away. In other words, localhost
only has ssh access to host1
, but host1
has ssh access to host2
. I want to copy my public ssh key from localhost
to host2
.
To copy a an ssh key to a remote host one hop away, the ssh documentation gives the command:
ssh-copy-id -i ~/.ssh/mykey user@host
Is there a way to copy the key to a machine that is two hops away in a single command?
Best Answer
You can pass any
ssh
option tossh-copy-id
with the-o
option. By using theProxyJump
option you can usessh-copy-id
to copy your key to a host via jump host.Here's an example where I copy my ssh key to leia.spack.org via the jump host jump.spack.org:
And then test it with: