Strovent SystemsSign in
Reference

ssh-copy-id through a jump host (ProxyJump)

ssh-copy-id has no -J flag, but it passes -o to ssh. Run ssh-copy-id -o ProxyJump=jump.example.com [email protected], or set ProxyJump in ~/.ssh/config.

ssh-copy-id has no -J option. It does pass -o options straight to ssh and sftp, so give it ProxyJump that way:

ssh-copy-id -o [email protected] [email protected]

Or put the jump in ~/.ssh/config and use the host alias. This is the better choice if you will connect again:

Host app
    HostName 10.0.0.5
    User user1
    ProxyJump [email protected]

Then run ssh-copy-id app. Plain ssh app uses the same settings afterwards.

What happens

  • You log in to the jump host first, with whatever works there: a key it already has, or its password.
  • Then you log in to the target, usually with its password. The first time, you are asked to accept the target's host key. If that fails, see Host key verification failed through a jump host (ProxyJump).
  • ssh-copy-id first tries each of your keys, to skip any the target already accepts. Then it appends the rest to ~/.ssh/authorized_keys on the target.

The key is not installed on the jump host. If you want key login there too, run ssh-copy-id [email protected] as well.

Pick the key

Without -i, ssh-copy-id copies the keys your agent lists (ssh-add -L). If the agent has none, it takes the newest ~/.ssh/id*.pub file. To be sure which key goes over, name it:

ssh-copy-id -i ~/.ssh/id_ed25519.pub -o [email protected] [email protected]

Use -n for a dry run that only prints the keys it would install.

If the target restricts commands

ssh-copy-id normally runs shell commands on the target. If the account cannot run them, add -s: it downloads authorized_keys with SFTP, changes it on your computer, and uploads it again.

Without ssh-copy-id

From any machine with OpenSSH, pipe the public key through the jump host yourself:

ssh -J [email protected] [email protected] 'mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys' < ~/.ssh/id_ed25519.pub

The chmod commands matter. By default sshd checks the modes and ownership of your home directory and key files, and will not use authorized_keys if it, ~/.ssh or your home directory is writable by other users. See Authorized keys and permissions.

Check that it worked

Turn off password login for one test connection, so a success can only come from the key:

ssh -o PasswordAuthentication=no -o [email protected] [email protected]

If the target still asks for a password or refuses you, the key was not accepted. Check the file permissions on the target, and that you copied the key you are now using.

Sources

Spotted a mistake? Email [email protected].