Pcornel
Browse topics
Options
Recent
Favorites
Linux · Technical reference

SSH Hardening

Direct answer

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.

When to use this

Use it when exposing SSH, or after an audit finding.

First 30 seconds

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).

Operational verification

connection allowed by firewall → modern key exchange → only allowed users → key authentication → logged

Evidence · next step

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
Platform / version applicability
linux
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

Platformlinux
Scope / prerequisiteUse it when exposing SSH, or after an audit finding.
What next?3 suggested next steps
Evidence1
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

5 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

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 references

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.

observation · 1
Key points

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.

Key checks
  • sestatus / aa-status — SELinux or AppArmor state
  • ss -tulpn — listening services
  • journalctl -u sshd -g 'Failed' — failed logins
  • ausearch -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:

SettingDefaultWhat to look for
PermitRootLoginprohibit-passwordno, or prohibit-password with no root keys
PasswordAuthenticationyesno on Internet-facing servers
KbdInteractiveAuthenticationyesno, unless used for OTP
AuthenticationMethodsanypublickey,keyboard-interactive where MFA is required
MaxAuthTries6Lower values slow down guessing
LoginGraceTime120 sShorter limits unauthenticated connections
AllowUsers / AllowGroupsEveryoneRestricted to an SSH group
AllowTcpForwardingyesno where tunnels aren't needed
X11Forwardingnono
LogLevelINFOVERBOSE 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

CheckCommand
Effective global settingssshd -T | grep -E '^(permitrootlogin|passwordauthentication|allowgroups|allowtcpforwarding)'
Settings for a specific user and addresssshd -T -C user=alice,host=x,addr=203.0.113.9
Who holds keysfind /home /root -name authorized_keys -exec wc -l {} +
Weak or unused keysssh-keygen -l -f per file, compared with recent logins
Accepted algorithmssshd -T | grep -E '^(ciphers|macs|kexalgorithms)'
ExposureFirewall rules for port 22; source restrictions
Login activityjournalctl -u ssh -g "Accepted|Failed"

Beyond sshd_config

MeasureEffect
Source restriction in the firewallMost scanners never reach sshd
fail2ban or ufw limitSlows down guessing from single addresses
A bastion host, or a VPN, in front of SSHOne controlled entry point
SSH certificatesShort-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.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.

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.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.

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
Technical verification history

Verification history & basis

When and against what this Topic was checked. Later text edits do not count as a new check.

2026-09-14 · vendor doclinux current

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%
Technical changelog & impact

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.

Related reference impactReview these references after material technical changes when their shared boundary is affected.
Terminology layer

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.

Aliases that resolve here
ssh hardeningopenssh hardeningsshd security
Embedded reference data

Quick lookup tables

SSH Hardening operational reference

Topic-specific lookup boundaries, proof limits and next-step Evidence for SSH Hardening.

Lookup boundaryTopic-specific referenceOperational use
Scope / effective stateSSH 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 verificationPin 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 chainnetwork path → host-key trust → algorithm negotiation → user authentication → account/key authorization → session/command/forwarding restrictions → audit → remote workloadTrace requested/configured state through effective state to the observed workload result.
Failure boundarySSH 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 evidenceCorrelated 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 workloadUse this observation only for the specific claim it actually supports.
Evidence limitIt 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 checkContinue 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 boundarySSH Hardening
Topic pathSecurity → SSH Hardening
Runtime stateSSH 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 chainnetwork 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 boundarySSH 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 ruleProve which configuration source owns the state, then prove that the running consumer loaded or generated the intended state.
Confirmation

Confirm action

Continue?