How to copy SSH keys to a server securely

How to copy SSH keys to a server securely

I much prefer SSH key authentication to password-based authentication when working with remote servers. One, it's one less password to remember. Two, on your machine, it's automatic. Three, it's more secure. So once you've got your server running, this is how you can copy your SSH key to it:

ssh-copy-id username@remote_host

This will copy your default SSH key from ~/.ssh/id_rsa.pub to the server. If you'd like to copy a different key instead, you can specify it using the -i parameter, like so:

ssh-copy-id -i ~/.ssh/mykey username@remote_host

And that's it! Your SSH key has been copied to your server securely!