Use it when exposing SSH, or after an audit finding.
SSH Hardening
SSH hardening reduces the risk of the SSH service: key-only authentication, no root password login, allowed users/groups, modern algorithms, rate limiting and restricting the source networks.
1. sshd -T | grep -E 'passwordauth|permitroot|allowgroups|kexalgorithms'.
2. Change in sshd_config.d/; sshd -t.
3. Reload and test login in a new session.
4. Firewall limits source networks?
5. Audit with ssh-audit <host> (if available).
connection allowed by firewall → modern key exchange → only allowed users → key authentication → logged
For Security → SSH Hardening, continue with the first unproven Topic check: Record exact host, distribution/kernel, boot ID, time window, workload, identity and the authoritative configuration/policy source for SSH Hardening. If that boundary is healthy, advance to the adjacent check: Read back the effective runtime state and precedence rather than assuming an edited file, package state or service status is active. Preserve the same host/time/identity scope and rerun the original workload before accepting recovery.
Continue only after interpreting the current observation.Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 Operational evidence path Verify boundary
network path → host-key trust → algorithm negotiation → user authentication → account/key authorization → session/command/forwarding restrictions → audit → remote workload
Healthy evidence: effective sshd policy matches intent, weak/unneeded methods are absent, keys/principals are scoped, restricted features behave as designed and required admin access remains recoverable
Step 2 Verification and output interpretation Verify boundary
Verification chain. network path → host-key trust → algorithm negotiation → user authentication → account/key authorization → session/command/forwarding restrictions → audit → remote workload
Step 3 Commands Verify boundary
sshd -T | grep -iE 'permitroot|password|maxauthtries|allowusers'
ssh-audit host
Step 4 Failure modes and next checks Narrow the fault
Suspicious evidence: effective config differs from edited file, root/password/forwarding paths remain broader than intended, stale/shared keys persist, host trust is bypassed, or hardening causes lockout without validated recovery
Step 5 Common mistakes Narrow the fault
- Disabling passwords before keys work for all admins.
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
Set PasswordAuthentication no, PermitRootLogin prohibit-password (or no), AllowGroups, and keep algorithms current. Combine with a firewall source restriction and fail2ban. Validate with sshd -t and test with a second session.
sestatus / aa-status— SELinux or AppArmor statess -tulpn— listening servicesjournalctl -u sshd -g 'Failed'— failed loginsausearch -m avc,user_login -ts today— audit events (auditd)
ReferenceImportant terms & boundaries5 sections · depth on demand
What this shows and what it does not
SSH hardening is resolved only when effective sshd configuration and key/identity policy produce the intended login, command, transfer and forwarding behavior without breaking required recovery access.
In depth
Auditing an SSH server's hardening
Hardening SSH means checking the effective configuration, not just the file. The sshd_config(5) manual page lists the settings and defaults that matter for security:
| Setting | Default | What to look for |
|---|---|---|
PermitRootLogin | prohibit-password | no, or prohibit-password with no root keys |
PasswordAuthentication | yes | no on Internet-facing servers |
KbdInteractiveAuthentication | yes | no, unless used for OTP |
AuthenticationMethods | any | publickey,keyboard-interactive where MFA is required |
MaxAuthTries | 6 | Lower values slow down guessing |
LoginGraceTime | 120 s | Shorter limits unauthenticated connections |
AllowUsers / AllowGroups | Everyone | Restricted to an SSH group |
AllowTcpForwarding | yes | no where tunnels aren't needed |
X11Forwarding | no | no |
LogLevel | INFO | VERBOSE records the key fingerprint for each login |
The same manual page explains the first-value rule and the Match blocks. Settings may be overridden by earlier lines, by included files or by Match conditions. Always check the result with sshd -T.
An audit sequence
| Check | Command |
|---|---|
| Effective global settings | sshd -T | grep -E '^(permitrootlogin|passwordauthentication|allowgroups|allowtcpforwarding)' |
| Settings for a specific user and address | sshd -T -C user=alice,host=x,addr=203.0.113.9 |
| Who holds keys | find /home /root -name authorized_keys -exec wc -l {} + |
| Weak or unused keys | ssh-keygen -l -f per file, compared with recent logins |
| Accepted algorithms | sshd -T | grep -E '^(ciphers|macs|kexalgorithms)' |
| Exposure | Firewall rules for port 22; source restrictions |
| Login activity | journalctl -u ssh -g "Accepted|Failed" |
Beyond sshd_config
| Measure | Effect |
|---|---|
| Source restriction in the firewall | Most scanners never reach sshd |
fail2ban or ufw limit | Slows down guessing from single addresses |
| A bastion host, or a VPN, in front of SSH | One controlled entry point |
| SSH certificates | Short-lived access instead of permanent keys |
host$ sudo sshd -T | grep -E "^(permitrootlogin|passwordauthentication|kbdinteractiveauthentication|allowgroups|maxauthtries|loglevel) "
permitrootlogin no
passwordauthentication no
kbdinteractiveauthentication no
maxauthtries 3
loglevel VERBOSE
allowgroups ssh-users
host$ sudo sshd -T -C user=vendor1,host=x,addr=203.0.113.9 | grep -E "^(passwordauthentication|allowtcpforwarding) "
passwordauthentication yes
allowtcpforwarding yes
host$ sudo grep -rn -A3 "^Match" /etc/ssh/sshd_config /etc/ssh/sshd_config.d/
host$ sudo find /root /home -name authorized_keys -exec sh -c 'echo "$1: $(grep -c . "$1")"' _ {} \;
Reading the per-user check
Globally, password logins are off. But for vendor1 from 203.0.113.9, a Match block enables both passwords and forwarding. Only the per-connection check (-C) reveals that exception. Review whether it's still justified.
Documented example, not captured output.
How it works at runtime
SSH Hardening is part of Security → SSH Hardening. SSH Hardening reduces remote-access exposure by proving effective sshd policy, host/user authentication, authorization, algorithm choices, forwarding limits, privilege boundaries and key lifecycle against the actual SSH workload.
Topic-specific state model. SSH Hardening reduces remote-access exposure by proving effective sshd policy, host/user authentication, authorization, algorithm choices, forwarding limits, privilege boundaries and key lifecycle against the actual SSH workload.
Interpretation rule. - Encrypted SSH ≠ trusted server identity or least-privilege authorization.
- A public-key login succeeds ≠ the key is unique, protected, current or sufficiently restricted.
Quick reference
SSH hardening checklist (/etc/ssh/sshd_config or drop-ins in sshd_config.d/):
PermitRootLogin no
PasswordAuthentication no
KbdInteractiveAuthentication no
PubkeyAuthentication yes
AuthenticationMethods publickey # or publickey,keyboard-interactive for MFA
AllowGroups ssh-users
MaxAuthTries 3
LoginGraceTime 30
X11Forwarding no
AllowTcpForwarding no # unless needed
ClientAliveInterval 300
ClientAliveCountMax 2
sshd -t && systemctl reload sshd
sshd -T | grep -Ei 'permitroot|passwordauth|allowgroups'
ssh-audit server01 # cipher/kex review
Restrict network access (firewall, bastion), use ed25519 keys, and consider SSH certificates (ssh-keygen -s ca) for large fleets.
Limits and how it fails
Primary failure point. SSH hardening is resolved only when effective sshd configuration and key/identity policy produce the intended login, command, transfer and forwarding behavior without breaking required recovery access.
ReferenceConfiguration & state1 section · depth on demand
Configuration, persistence and lifecycle
Distribution/platform context. SSH Hardening owns security posture; the SSH branch owns protocol/session operation and SSH Troubleshooting owns failure isolation.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in Security → SSH Hardening. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://docs.kernel.org/security/index.html · confidence 94%What changed and what may be affected
Recent technical edits are separated from ordinary page timestamps. Relationship impact is advisory: it identifies nearby canonical references to review, not automatic breakage.
Terms & aliases
Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.
Quick lookup tables
SSH Hardening operational reference
Topic-specific lookup boundaries, proof limits and next-step Evidence for SSH Hardening.
| Lookup boundary | Topic-specific reference | Operational use |
|---|---|---|
| Scope / effective state | SSH Hardening reduces remote-access exposure by proving effective sshd policy, host/user authentication, authorization, algorithm choices, forwarding limits, privilege boundaries and key lifecycle against the actual SSH workload. | Establish exactly what this Topic owns before crossing into another subsystem. |
| Fast verification | Pin host + boot/time + real identity/workload → identify authoritative policy/key/trust source → read back loaded/effective runtime state → reproduce one safe allow/deny/handshake test → correlate audit/service/kernel evidence → locate first failed boundary → make the smallest persistent change → repeat original workload + regression/recovery check. | Use the shortest evidence path first; a fast check is a boundary test, not blanket proof. |
| Verification chain | network path → host-key trust → algorithm negotiation → user authentication → account/key authorization → session/command/forwarding restrictions → audit → remote workload | Trace requested/configured state through effective state to the observed workload result. |
| Failure boundary | SSH hardening closes only when effective sshd configuration and key/identity policy produce the intended login, command, transfer and forwarding behavior without breaking required recovery access. | Stop broad troubleshooting at the first boundary that is not supported by evidence. |
| Positive evidence | Correlated Linux security/trust evidence can establish this proof path: network path → host-key trust → algorithm negotiation → user authentication → account/key authorization → session/command/forwarding restrictions → audit → remote workload | Use this observation only for the specific claim it actually supports. |
| Evidence limit | It does not independently prove unobserved identities, objects, policies, namespaces, endpoints or time periods. SSH hardening closes only when effective sshd configuration and key/identity policy produce the intended login, command, transfer and forwarding behavior without breaking required recovery access. | Do not promote a local success signal into end-to-end or adjacent-dependency proof. |
| Next troubleshooting check | Continue from the first unproven security/trust boundary, capture the adjacent effective state and audit/handshake evidence, make only the demonstrated persistent change, then repeat the original workload plus recovery/regression checks. | Continue to the next unresolved boundary while preserving the original test condition. |
SSH Hardening · operational reference
Compact Linux state, persistence, verification and boundary reference for fast lookup.
| Reference boundary | SSH Hardening |
|---|---|
| Topic path | Security → SSH Hardening |
| Runtime state | SSH Hardening reduces remote-access exposure by proving effective sshd policy, host/user authentication, authorization, algorithm choices, forwarding limits, privilege boundaries and key lifecycle against the actual SSH workload. |
| Fast checks | - Record exact host, distribution/kernel, boot ID, time window, workload, identity and the authoritative configuration/policy source for SSH Hardening. - Read back the effective runtime state and precedence rather than assuming an edited file, package state or service status is active. - Reproduce one safe allowed/denied or handshake/access test and correlate kernel/service/audit evidence at the first relevant boundary. - Apply the smallest persistent cause-specific change, then repeat the original test plus an adjacent regression/recovery check. |
| Verification chain | network path → host-key trust → algorithm negotiation → user authentication → account/key authorization → session/command/forwarding restrictions → audit → remote workload Boundary chain: local authoritative state → adjacent dependency → effective/programmed state → original workload/request → return/regression → explicit Evidence boundary. Boundary chain: local authoritative state → adjacent dependency → effective/programmed state → original workload/request → return path or regression → explicit Evidence boundary. |
| Failure boundary | SSH hardening closes only when effective sshd configuration and key/identity policy produce the intended login, command, transfer and forwarding behavior without breaking required recovery access. Boundary chain: process/context → userspace configuration → kernel subsystem/resource → device/network/filesystem dependency → effective state → original workload. |
| Persistence rule | Prove which configuration source owns the state, then prove that the running consumer loaded or generated the intended state. |