Note: This article was originally published in 2020. Some steps, commands, or software versions may have changed. Check the current Ubuntu documentation for the latest information.

Prerequisites

Before you begin, make sure you have:

  • A system running Ubuntu (desktop or server edition)
  • Terminal access with sudo privileges
  • Basic familiarity with Linux command line

I’ve had a few servers I was logging in using username and password and I kind of liked how Azure uses an ssh key for logging in (plus the fact it is more secure) so I decided to install my ssh key on all our servers. The ssh-copy-id command (in the openssh-client  package and installed by default) does exactly this:

ssh-copy-id [email protected]

copies the public key of your default identity (use -i identity_file for other identities) to the remote host.

This makes life so much easier, as it makes you log in, checks the key is not already present on the destination server, copies over the key and all! Just the kind of thing I love :3

Summary

You’ve successfully learned add ssh keys easily to another machine. If you run into any issues, double-check the prerequisites and ensure your Ubuntu environment is properly configured.