>_ IzzyLab

Hands-on task

This task is step 5 of the course “New server: setup from scratch”

Lock passwords and root out of sshd

medium~7 min

The provider's image came with SSH wide open: /etc/ssh/sshd_config allows logging in as root, and cloud-init dropped its own snippet into /etc/ssh/sshd_config.d/ that turns on password login. You've already handed out keys to the team — make the effective sshd configuration forbid both password login and root login (value no for both).

What you'll practise:
  • sshd_config
  • sshd_config.d
  • Include
  • first occurrence
  • sshd -T

Topic breakdown

The SSH server's configuration is /etc/ssh/sshd_config plus everything pulled in by the Include directive. On Ubuntu it sits at the very top of the file and loads /etc/ssh/sshd_config.d/*.conf, where cloud-init and packages like to write. For most directives sshd uses the first value it meets, so a snippet from sshd_config.d/ wins over a line further down in the main file — appending what you need to the end isn't enough. The reliable way to see what actually applies is sshd -T: it prints the effective configuration after all Includes, and sshd -t checks the syntax.

What's checked

  1. the sshd configuration is valid
  2. password login is forbidden
  3. root login is forbidden

What it looks like