>_ IzzyLab

Hands-on task

This task is step 4 of the course “SSH: keys and access”

Authorize a Public Key

medium~5 min

A colleague needs to log into this server over SSH. Their public key is in /root/given.pub. Allow login with this key for the user root by adding it to the right file. root already has one authorized key — it must keep working. And check the permissions: sshd won't accept keys if they are too open.

What you'll practise:
  • authorized_keys
  • ssh
  • public keys
  • appending to a file

Topic breakdown

Key-based login works like this: the SSH server lets in the user whose public key is listed in their personal ~/.ssh/authorized_keys file — each allowed key on its own line. To grant access, the contents of the public key must be placed into this file of the target user. It's important to append the key at the end (the >> operator) rather than overwrite the file (>), otherwise the already-allowed keys will be lost; the ~/.ssh directory is created beforehand if needed.

What's checked

  1. key authorized
  2. the previous key is preserved
  3. permissions on ~/.ssh and authorized_keys are strict

What it looks like