ND-0009 / LINUX OPERATIONS
Harden SSH Without Locking Yourself Out
The old SSH window still works. A second terminal gives you a prompt. Before you close either one, find out whether the second terminal actually authenticated. OpenSSH can share a connection through a control socket, so a second terminal can open a session on an already authenticated connection. That can hide a bad configuration until […]
The old SSH window still works. A second terminal gives you a prompt. Before you close either one, find out whether the second terminal actually authenticated. OpenSSH can share a connection through a control socket, so a second terminal can open a session on an already authenticated connection. That can hide a bad configuration until the next shift tries to log in.
Keep a way back
Rehearse on a disposable Ubuntu 24.04 VM you control. Before editing, open the VM or hosting console and confirm that you can get an administrative shell there. Keep the original SSH session open. Save a known-good copy of the files you plan to change. If you cannot use the console or do not know which files to restore, stop here. Leave the listener address, port, firewall, and sudo policy unchanged during this exercise.
Check the configuration for your actual login
From the server, run the syntax check and inspect the candidate policy for the intended account and source. Replace the example values with the lab values the server actually sees. The host field is the resolved source hostname, not the destination. Include local address and port when your policy matches on them.
sudo sshd -t
sudo sshd -T -C user=lab-admin,addr=192.0.2.24,host=lab-client,laddr=192.0.2.10,lport=22
Check pubkeyauthentication, passwordauthentication, kbdinteractiveauthentication, and authenticationmethods against your intended policy. A password prompt and a keyboard-interactive MFA prompt are not the same thing. Do not switch off keyboard-interactive just because the goal is to remove password-only login. Check included files and applicable Match blocks before assuming your edited line wins. These checks examine files, not the running login path. Ubuntu sshd manual · Ubuntu sshd_config manual
Make the new session authenticate
After syntax and effective policy checks pass, apply the validated change with the procedure documented for your distribution. For the Ubuntu service procedure, see Ubuntu OpenSSH Server documentation. From the normal admin client and path, connect without sharing a target connection:
ssh -S none lab-admin@lab-host
Confirm the intended account and hostname in the fresh session. Verify the expected method in the server’s authentication logs and complete any required MFA. In the lab, check separately that the method you meant to disable is not accepted; a network failure or a host-key prompt does not count. If the normal path includes a jump host, distinguish authentication there from authentication on the destination. OpenSSH client option reference
Rollback is part of the test
If any fresh login or policy check fails, leave the original session alone. Use the verified console to restore the known-good files. Check syntax again, apply the restored configuration, and prove a fresh login on the original policy before closing either recovery path. Log the outcome and keep the console open until the team can repeat the intended login.
What we verified
On Debian 13 with OpenSSH 10.0p2, a temporary configuration passed sshd -t. sshd -T -C reported password authentication disabled for the source covered by a sample Match rule and enabled for a different source. With a client config that specified a control socket, ssh -G reported that path; adding -S none removed the path from the effective output. Those were configuration checks. We did not run an Ubuntu service reload, live login, MFA, or rollback in that test.