Peters School of Business · Assiniboine College · NETW-0014
2 hours · Lab 1D Parts 3–4 · sshd_config, banners, idle timeout, AllowUsers
Key auth confirmed, sshd_config walkthrough
/etc/ssh/sshd_config on S1 together. Walk through the structure: commented-out lines show default values. Active lines override the defaults. Ask: "What happens if you save the file with a typo in a directive name?" — SSH daemon may refuse to start on next restart. Good habit: always run sudo sshd -t (config test) before restarting SSH.sudo systemctl restart ssh. And every change should be tested immediately from a second terminal — never close your current session until you've confirmed the new session works.Apply production-grade SSH hardening: disable password auth, change port, banners, timeout, access controls
Part 3a — Disable password authentication (15 min)
/etc/ssh/sshd_config, find the line #PasswordAuthentication yes. Uncomment it and change to no:
PasswordAuthentication no
ChallengeResponseAuthentication no is set — on some Ubuntu versions this can override PasswordAuthentication if left enabled.
sudo sshd -t — no output means the config is valid. Restart: sudo systemctl restart ssh.-o PubkeyAuthentication=no to force password mode:
ssh -o PubkeyAuthentication=no student@[S1-IP]
Permission denied (publickey). This confirms password auth is disabled. If you still get a password prompt, check the config file for a second PasswordAuthentication line (some Ubuntu versions have one in a Match block at the bottom).
Part 3b — Change the SSH port (10 min)
#Port 22. Uncomment and change to a non-standard port, e.g. Port 2222.-p 2222 to the SSH command. Test the connection on the new port before proceeding.Part 3c — Authentication security settings (15 min)
LoginGraceTime 30 — close the connection if the user hasn't authenticated within 30 seconds. Default is 120 — too generous.
MaxAuthTries 3 — only allow 3 authentication attempts per connection. Default is 6. Lowering this reduces the window for automated attacks.
MaxSessions 5 — limit concurrent sessions per connection. Default 10 is excessive for a server.
PermitRootLogin no — never allow direct root login over SSH. Root should always be accessed by logging in as a regular user and using sudo.
AllowUsers student
AllowUsers student admin (space-separated).
Part 4a — Configure the idle timeout (15 min)
/etc/profile on each server. Add these three lines at the bottom:
TMOUT=300
readonly TMOUT
export TMOUT
readonly prevents users from unsetting it.
timed out waiting for input: auto-logout.Part 4b — Configure login banners (20 min)
Banner /etc/ssh_banner in sshd_config.
/etc/motd.
sudo nano /etc/ssh_banner. Add a warning message, for example:
*************************************************************
* AUTHORISED ACCESS ONLY *
* This system is monitored. Unauthorised access is illegal. *
*************************************************************
Banner /etc/ssh_banner. Restart SSH and verify the banner appears when connecting.
sudo nano /etc/motd. The lab sheet includes ASCII penguin art — copy it in. The MOTD is shown immediately after the login prompt. Students can customise their penguin or add server info (hostname, date, reminder to take snapshots).Reading auth.log — a preview of fail2ban
sudo tail -f /var/log/auth.log — watch the log live while attempting connections from a second terminal.Learning outcomes — by end of Day 4, students can…
Common issues and fixes
| Issue | Likely cause | Fix |
|---|---|---|
| Password auth still works after setting PasswordAuthentication no | Second PasswordAuthentication directive in a Match block at file bottom, or PAM override | Search for all occurrences: grep -n PasswordAuthentication /etc/ssh/sshd_config. Also check /etc/ssh/sshd_config.d/ — Ubuntu 22+ may include a drop-in file that overrides the main config |
| Locked out after changing SSH port | Windows Terminal profile not updated, or firewall blocking new port | Connect via Hyper-V console. Update the port in sshd_config back to 22 temporarily, restart, then update Windows Terminal and change the port again |
| AllowUsers blocks the student account | Username typo or case sensitivity (Linux usernames are case-sensitive) | Verify exact username: whoami on the server. Correct the AllowUsers line and restart SSH |
| SSH banner not appearing | Banner directive not pointing to the correct file path, or sshd not restarted | Verify the file exists: ls -l /etc/ssh_banner. Check the directive in sshd_config matches the path exactly. Restart SSH |
| TMOUT not working in existing sessions | TMOUT only applies to new sessions | Log out completely and open a new SSH session. The TMOUT setting is read at shell startup |