SSH keys

SSH keys

Using a key file can greatly increase security when connecting to a host via SSH. This article presents how to create such keys and configure hosts to use them.

First, a SSH key can be created on a local host using the ssh-keygen command:

ssh-keygen

ssh-keygen will prompt the user for a filename as well as an optional password for the keys. In this example, let's assume that the chosen filename was myKey.

ssh-keygen will generate two files: myKey and myKey.pub. Those are the private and public keys respectively.

The public key must be registered on any hosts that we want to connect to. This can be achieved using ssh-copy-id:

ssh-copy-id -i myKey.pub username@serverip

Where username and serverip are to be replaced by the corresponding values of the server to connect to.