>_ IzzyLab

Hands-on task

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

Harden sshd

medium~7 min

Harden the SSH server settings (/etc/ssh/sshd_config and everything it includes): disable password login (keys only) and forbid root superuser login. The effective values of both settings must end up "disabled".

What you'll practise:
  • sshd_config
  • sshd directives
  • first occurrence
  • sshd -T
  • server hardening

Topic breakdown

The behavior of the SSH server is controlled by directives in /etc/ssh/sshd_config — one per line, in the form Directive value; commented-out (#) lines are merely inactive defaults. You need two directives: one controls password login, the other controls root login (look up their names in man sshd_config by the descriptions "password authentication" and "root login"), and both are set to no. The key nuance: sshd takes the first occurrence of a directive, and Include drops the files from sshd_config.d/ in right where it stands — cloud images like to put their own settings there. So appending a line at the end is not enough — existing lines with a different value have to be found and fixed. sshd -T shows the effective config.

What's checked

  1. sshd configuration is valid
  2. password login disabled
  3. root login disabled

What it looks like