>_ IzzyLab

Hands-on task

This task is step 6 of the course “Server: first steps”

Create an SSH key

easy~4 min

To log in to servers without a password, you need your own SSH key — a pair of a private and a public key.

Create a key pair of type ed25519 in the standard location: the private key is /root/.ssh/id_ed25519, the public one is /root/.ssh/id_ed25519.pub. Set a passphrase or leave it empty — up to you.

What you'll practise:
  • ssh-keygen
  • ed25519
  • private and public key
  • ~/.ssh

Topic breakdown

Logging in with an SSH key is safer than a password: a key can't be brute-forced or peeked over your shoulder. A key is a pair of files:

  • the private key stays with you only and is never handed to anyone. If it's stolen, anyone can log in;
  • the public key (the file ending in .pub) is safe to give out: put it on servers, send it to colleagues, paste it into GitLab.

ssh-keygen creates the pair. The -t flag sets the type. The recommended one today is ed25519 — short, fast and strong keys. The old rsa type still turns up too, and on older systems ssh-keygen without -t creates exactly that, so it's better to give the type explicitly.

By default keys are kept in the ~/.ssh directory in your home directory, and ssh finds them there by their standard names — so it's best to accept the path ssh-keygen suggests. This is what the prompts look like for the user bob:

$ ssh-keygen -t TYPE
Enter file in which to save the key (/home/bob/.ssh/id_ed25519):
Enter passphrase (empty for no passphrase):

A passphrase encrypts the private key: even someone who steals the file can't use it. People usually set one for their own keys and leave it empty for keys used by scripts and CI.

What's checked

  1. Both keys are in the standard location
  2. The key is of type ed25519
  3. The private and public keys are one pair
  4. Only the owner can access the private key

What it looks like