SSH and account hardening
Quick answer
SSH hardening reduces unnecessary login methods and administrative exposure while keeping legitimate recovery access. Start from known-good authentication and review effective policy before any change.
Test authentication and authorization separately: a valid login need not grant administrative access. Preserve host identity verification and a known recovery path, and validate new sessions in a private VM before retiring the previous access method.
Prepare the practice environment
Run python3 lab-fixtures/security/setup.py from the extracted root as an ordinary user. Enter the printed fresh private path and check pwd. Use fresh fixtures, Bash with set -e -o pipefail, LC_ALL=C and umask 077. Run each snippet in a separate Bash process, not your interactive shell. Only private files are used; optional examples require an authorized snapshot VM. Do not modify system services or security policy. Review the lab guide.
Prerequisites
Review: Updates and package integrity.
How it works
Use a named administrative account, authorized public keys, strong credential handling and narrowly delegated sudo. PermitRootLogin no denies direct root SSH login; PasswordAuthentication no disables that method but keyboard-interactive and other methods are separate. The supplied snippets are fictional partial policies, not complete deployable configurations. Includes, Match blocks and distribution defaults can alter effective settings; sshd -T reports effective settings and -C can supply connection context. Before changing a real policy in an authorized VM, retain a working session, verify independent console access, back up configuration, validate with sshd -t, test a new authorized login after controlled reload and keep rollback available. Do not disable MFA or remove the only working login path.
Try the examples
grep -E '^(PermitRootLogin|PasswordAuthentication|PubkeyAuthentication)' sshd.sampleThis extracts literal lines, not effective configuration. The candidate assumes a verified public-key login and separate recovery console.
Expected stdout:
PermitRootLogin noPasswordAuthentication noPubkeyAuthentication yesThe file represents prerequisites to a change; it is not proof of actual successful access.
Expected stdout:
console=verifiedkey-login=verifiedrollback=availableOptional read-only command on an authorized disposable SSH server VM with host keys and required runtime paths. Output varies and may require privileges. Do not reload or change authentication policy here.
Manual example; not executed locally. Follow its stated environment restrictions.
Common mistakes
Do not replace a real sshd configuration with this partial sample or confuse grep output with effective policy. Preserve host verification and approved MFA.
Practice
Review sshd.sample and access-plan.txt. Write a safe change sequence with independent console recovery and a new-login verification step.
Related references
Study: sshd. These are reference names, not deployed links.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
SSH and account hardening — Knowledge Check
Apply defensive security concepts to synthetic fixtures and VM-only scenarios.
What does PermitRootLogin no restrict?
Does PasswordAuthentication no disable every password-like method?
What is sshd -T useful for?
What should remain available during access changes?