Case File: The Setting That Was Ignored
An administrator added PermitRootLogin no at the bottom of the SSH server configuration and believed the door was shut. The line was ignored: sshd uses the first value that it finds. Audit a configuration file the way the server reads it: first value wins, defaults for missing keywords, Match blocks kept apart, and a list of findings. Run the audit on files you cannot see. The file is generated for you alone.
Sabi Logistics · Remote 1
The Setting That Was Ignored
The scan says that root can still log in over SSH, although the team added a line to forbid it last month
Chidi Engineering manager ·
Chidi. The security scan of the build server says that root can log in over SSH with a password. I do not believe it. Last month one of our people added PermitRootLogin no to the file, and I saw the ticket closed.
I opened the file. The line is there, at the bottom. And three hundred lines above it, from the install, there is another PermitRootLogin yes. I am not an expert. Which one is the server using? Please write a check that reads the file the way the server reads it, and tells us what is really in force, so that we can run it on every machine we own.
The brief
What you need to know first.
- First value wins. For most keywords,
sshdtakes the first value that it finds and ignores later ones. A line added at the end of the file does not change a setting that was already given above it. That is the opposite of what most configuration files do, and it surprises everybody once. - Match blocks. A
Matchline (for exampleMatch User backup) starts a block of settings that apply only to those users or addresses, and it runs until the nextMatchline or the end of the file. The lines under it are not global settings: do not let them change the global values, but report if a Match block turns onPasswordAuthenticationorPermitRootLogin. - Read the file. Strip each line; skip empty lines and lines that start with
#. The keyword is the first word (case-insensitive), the value is the rest in lower case. Before the first Match line, keep the first value of each keyword in a dict; a later line with a different value isignored_duplicate:KEYWORD(the same value again is no problem). - Defaults and findings (sorted, each once):
root_login(PermitRootLoginisyes; missing meansprohibit-password, which is fine);password_auth(notno; missing means yes);empty_passwords;max_auth_tries(above 4; missing means 6, so it is a finding);x11_forwarding;no_allow_list(noAllowUsersand noAllowGroups);match_allows_password;match_allows_root. - Fill in
audit(lines),findingsandn_findings. The checks runauditon files you cannot see: one where the safe line is first and an unsafe one is ignored, one where the unsafe line is first, and an empty file (all the defaults).
The lab gives you the data for this case, invented and generated for you alone. Today is 2026-11-09.
Preparing your data…
On a real system
The lab modelled the rules with a script. These are the commands that you would type on the real thing.
| You want to | Type | What you get |
|---|---|---|
| see what the SSH server will really use | sudo sshd -T | every setting after all the files and defaults, one per line |
| test a configuration file before reloading | sudo sshd -t | prints an error if the file is wrong, and nothing if it is fine |
| see one setting in the files that sshd reads | grep -ri permitrootlogin /etc/ssh/sshd_config /etc/ssh/sshd_config.d/ | every line that sets it, in every file |
Only run commands on systems that you own or have written permission to test.
Chidi: “The audit says that root login is still on, because the first line wins. We fixed the file. A colleague asks how we make sure that nobody adds a line in the wrong place again.”
🔒 The debrief unlocks when you close the case. Finish the lab above.
The debrief
Chidi: “So the file should be written in a way that cannot hide a setting, and checked by a machine.”
What a senior administrator would do next. Put your settings in a drop-in file (/etc/ssh/sshd_config.d/10-hardening.conf, read before the main file on current systems) so that they come first and are in one short file that anyone can read. Always check the effective configuration with sshd -T (it prints what the server will really use, after all the files and defaults) and test a change with sshd -t before you reload, and keep a second session open while you reload, so that a mistake does not lock you out. Run an audit like this one from the configuration management tool on every machine, and alert on a difference from the standard. Know the defaults of your version, since they change (newer OpenSSH versions are safer by default). The usual hardening list is: key logins only, no root login, an allow list of users or groups, a low MaxAuthTries, no X11 forwarding, no empty passwords, and modern ciphers. Port 22 versus another port is not a security control: it only reduces noise in the logs. And use fail2ban or a similar tool and a firewall, so that the machine is not open to the whole internet.
The trap. Reading the file like a story. The server reads it from the top and stops at the first value.
Write the SSH audit note
Write the note for the engineering manager: how sshd reads the file (the first value wins, Match blocks are kept apart, defaults for missing keywords), what your audit found and why each finding matters, why a line added at the end of the file did not take effect, and how to prevent it (a drop-in file that is read first, sshd -T and sshd -t, a second session when reloading, configuration management with an audit, key-only logins, an allow list, fail2ban and a firewall).
🧪 Want to practise this on your own computer? See how to set up your lab →