>_ IzzyLab

Hands-on task

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

Let a colleague in with a key

easy~6 min

Anna has joined the team and needs access to the server. She sent her public key — it's in /root/anna.pub.

Set things up so that Anna can log in with this key as the user deploy (that user already exists). The directory and the file with the keys must belong to deploy and be accessible only to that user: that's the rule, and if someone else can change them, SSH won't accept the key.

What you'll practise:
  • authorized_keys
  • chown
  • chmod
  • ~/.ssh permissions
  • key login

Topic breakdown

How a server lets you in with a key: every user can have a file ~/.ssh/authorized_keys in their home directory — a list of public keys that can log in as that user, one key per line. When someone connects, the server checks whether they hold the private key for one of the public keys on that list. The private key itself never travels over the network.

So to let someone in, they don't need your password, and you don't need their private key: it's enough to add their public key to the right user's authorized_keys.

The SSH server (sshd) is strict about permissions: if the .ssh directory or the authorized_keys file belongs to another user (not root), or someone else can change them, it silently rejects the key. This is how it should look:

/home/bob/.ssh                    drwx------  bob bob   (700)
/home/bob/.ssh/authorized_keys    -rw-------  bob bob   (600)

chown user:group path changes the owner (-R for a directory and everything in it), and chmod changes permissions.

What's checked

  1. Anna's key is in the deploy user's key list
  2. The .ssh directory and the keys file belong to deploy
  3. Only the owner can access the .ssh directory and the keys file

What it looks like