Copying SSH Keys between different hosts


How to copy SSH keys between Linux hosts and from Windows to Linux.

Copy SSH key between Linux hosts

ssh-copy-id <user>@<ip-address>

# if target machine's hostname is in /etc/hosts
ssh-copy-id <user>@<hostname>

Copy SSH key between Windows and Linux

cat ~/.ssh/id_rsa.pub | ssh <user>@<hostname> 'cat >> .ssh/authorized_keys && echo "Key copied"'

The above command will fail if the .ssh folder does not already exist on the Linux host. Below is a more advanced command that will create the folder and give it correct permissions.

cat ~/.ssh/id_rsa.pub | ssh <user>@<hostname> 'umask 0077; mkdir -p .ssh; cat >> .ssh/authorized_keys && echo "Key copied"'

Next: GitHub Docs instructions for adding a GPG keys.

Generating an SSH key pair

Setup SSH authentication to push to Github