Hardening guide

Linux SSH hardening baseline that does not lock you out

A practical OpenSSH baseline for reducing password, root-login, forwarding, and brute-force risk while keeping a tested rollback path.

BlackShield Research8 min read25 min implementation
Hardening guideLinuxOpenSSHintermediate

Why this matters

SSH is often the last administrative door left open when every other management plane is broken. The useful baseline is not 'turn everything off'; it is to keep key-based access working, remove password and root-login paths, and test syntax before the daemon reloads.[source-1, source-2]

Prescriptive baseline

Apply this in a staged maintenance window while keeping an existing administrative session open.

  1. 1Confirm at least one non-root admin user can authenticate with a public key.
  2. 2Write the hardening file under sshd_config.d rather than editing distribution defaults directly.
  3. 3Run the sshd syntax check before reload; do not close the existing session until a new session succeeds.
  4. 4Record the changed file and validation result as remediation evidence.
[source-1, source-2]
/etc/ssh/sshd_config.d/99-blackshield-hardening.confsshconfig
PermitRootLogin no
PasswordAuthentication no
KbdInteractiveAuthentication no
PubkeyAuthentication yes
MaxAuthTries 3
AllowTcpForwarding no
X11Forwarding no

Keep an existing root or sudo session open until sshd -t passes and a new key-based session works.

[source-1, source-2]
Validate and reload safelybash
sudo sshd -t
sudo systemctl reload ssh || sudo systemctl reload sshd
ssh -o PreferredAuthentications=publickey admin@example-host

If validation fails, remove the drop-in file from the still-open session and reload the daemon.

[source-1, source-2]

Rollback and evidence

  • Rollback: remove the drop-in file and reload ssh or sshd from the existing session.
  • Evidence: keep the drop-in file path, sshd -t output, reload timestamp, and a successful non-root key-based login record.
  • Monitoring: track repeated failed SSH authentication and unexpected changes to sshd configuration.
[source-1, source-3]

BlackShield context

BlackShield can keep this as owner-assigned remediation work with validation evidence attached, rather than a one-off hardening note that disappears after the maintenance window.

Affected systems and scope

Treat this topic as a scoping exercise before it becomes a queue of tickets. The systems in scope include Linux servers, bastion hosts, cloud VMs, administrative jump boxes, emergency access paths, and monitored SSH daemon configuration. Inventory alone is not enough: the responder has to know whether the asset is production, externally reachable, ownerless, business critical, or covered by an accepted exception. That context prevents a shallow severity score from driving every decision and lets teams separate urgent exposure from routine hardening work.[source-1, source-2, source-3]

Exposure path

The exposure path is the chain that turns a public recommendation into tenant risk: SSH risk increases when password authentication, root login, forwarding, weak retry limits, or unmanaged configuration drift remain available on reachable hosts. A good investigation writes that chain down in plain language, including what is verified, what is assumed, and what still needs a bounded check. That discipline matters because teams often over-rotate on the public headline while missing the local preconditions that decide whether immediate remediation, temporary isolation, or planned maintenance is the right response.[source-1, source-2, source-3]

Detection and triage

Detection should start with evidence that can be repeated by another operator. For this topic, sshd configuration, authentication logs, running daemon state, Wazuh or OSSEC alerts, package posture, and failed-login patterns should be reviewed before and after rollout. Triage is stronger when it records negative evidence as well as positive matches, because a clean result from one scanner may only mean that the scanner could not see a host, region, namespace, package manager, or runtime path. The response owner should preserve enough context for a later reviewer to understand why the finding was prioritized, deferred, or closed.[source-1, source-2, source-3]

A defensible triage note should answer these questions before work is assigned:

  • Which production assets, repositories, accounts, or services match Linux servers, bastion hosts, cloud VMs, administrative jump boxes, emergency access paths, and monitored SSH daemon configuration?
  • Which of those assets are exposed to users, partners, the Internet, or high-privilege internal networks?
  • Who owns the service and who can approve downtime, rollback, exception, or compensating-control decisions?
  • Which scanner, configuration, log, or inventory result supports the current status, and when was it collected?
  • What uncertainty remains, and what is the next smallest probe that can reduce it without expanding scope?
[source-1, source-2, source-3]

Investigation workflow

A mature response should move through the same sequence even when the topic feels urgent: confirm the asset set, confirm the risky condition, confirm reachability, confirm ownership, choose the response path, and capture validation evidence. The order matters. Teams that jump straight to patching can miss unsupported assets, regional copies, unmanaged hosts, old containers, or exceptions that need leadership approval. Teams that stay in analysis too long can leave a reachable weakness open while arguing over perfect certainty. The workflow should make the next bounded action obvious.[source-1, source-2, source-3]

Use this as the minimum investigation spine for a new finding or hardening gap:

  1. 1Inventory the systems that could match Linux servers, bastion hosts, cloud VMs, administrative jump boxes, emergency access paths, and monitored SSH daemon configuration, including stale or secondary deployment paths.
  2. 2Split the matching set by exposure, business criticality, owner, and ability to change within the current window.
  3. 3Collect the first reusable evidence package from sshd configuration, authentication logs, running daemon state, Wazuh or OSSEC alerts, package posture, and failed-login patterns should be reviewed before and after rollout, and record coverage limits beside the result.
  4. 4Select patch, configuration hardening, isolation, monitoring, exception, or retirement as the response path for each asset group.
  5. 5Validate closure with operators should keep sshd test output, the drop-in file, reload timestamp, successful key-based login proof, and monitoring evidence for rejected password attempts, then keep the evidence where future reviewers can find it.
[source-1, source-2, source-3]

Compensating control review

Compensating controls are useful when they materially change attacker opportunity, not when they merely postpone a difficult change. For SSH risk increases when password authentication, root login, forwarding, weak retry limits, or unmanaged configuration drift remain available on reachable hosts, the control review should ask whether the risky path is now unreachable, less privileged, more observable, or isolated from sensitive data and production dependencies. The review should also name the expected failure mode: what signal would show that the temporary control stopped working, and who is accountable for reacting before the exception expires.[source-1, source-2, source-3]

Operational handoff

The handoff from security to engineering should be specific enough that the assignee can act without reverse-engineering the advisory. Include the affected resource, the observed evidence, the required change, the validation command or scanner check, the rollback note, and the deadline. If a team rejects the recommendation, capture the reason and compensating control in the same record. That makes risk acceptance visible as a managed decision rather than an unresolved comment thread.[source-1, source-2, source-3]

Remediation and compensating controls

The remediation plan should be short enough to execute and specific enough to audit. In this case, rollout should preserve an open session, test syntax, verify key-based non-root access, and stage changes through lower-risk host groups before broad enforcement. If the preferred fix cannot land immediately, the compensating control should reduce reachability, reduce privilege, increase monitoring, or isolate the affected component while keeping an owner and expiry date attached. Temporary controls are useful only when everyone can see that they are temporary and when the validation step proves they still cover the risk.[source-1, source-2, source-3]

Evidence areaWhat to retain
ScopeInventory or query output covering Linux servers, bastion hosts, cloud VMs, administrative jump boxes, emergency access paths, and monitored SSH daemon configuration
Risk decisionOwner, priority, exception status, and rationale for the selected response path
ChangePatch, configuration, policy, workflow, or isolation record tied to the affected asset
Validationoperators should keep sshd test output, the drop-in file, reload timestamp, successful key-based login proof, and monitoring evidence for rejected password attempts
[source-1, source-2, source-3]

Operational pitfalls

  • Changing the main distribution config file makes package updates and rollback harder than a controlled drop-in file.
  • Closing the only privileged session before testing a new login can turn a hardening task into an outage.
  • Disabling passwords without checking break-glass accounts can strand incident responders during a separate failure.
  • Forwarding controls need owner review where developers use bastions for legitimate administrative tunnels.
[source-1, source-2, source-3]

Validation evidence

Validation is where a security update becomes an operationally useful record. For this article, operators should keep sshd test output, the drop-in file, reload timestamp, successful key-based login proof, and monitoring evidence for rejected password attempts. The evidence should be durable enough to survive a staff change, an audit request, or an incident review months later. A screenshot may help, but machine-readable output, ticket links, scanner run identifiers, command transcripts, and timestamps are easier to compare across teams and reruns.[source-1, source-2, source-3]

The validation package should be complete enough for a second operator to repeat the conclusion:

  • Before evidence that shows the original risky condition, including the asset identifier, scope boundary, and collection time.
  • Change evidence that shows what was altered, who approved it, and which maintenance or deployment window carried the work.
  • After evidence from a different check where possible, proving the running service, deployed artifact, cloud control, or policy state changed.
  • Exception evidence for any remaining risk, with owner, compensating control, expiration date, and the reason permanent remediation cannot happen yet.
  • Monitoring evidence that would surface regression, failed rollout, abuse of the affected path, or drift back to the old configuration.
[source-1, source-2, source-3]

Archive quality

Forward-looking public articles should remain useful after the first news cycle. That means the reader should be able to understand the issue, decide whether it applies, choose a bounded first probe, see what evidence matters, and avoid predictable rollout mistakes. Short posts can announce that something happened; a research archive should help a defender make and justify an operational decision. This is why new automated and checked-in articles carry the 8-minute floor while older remote posts remain valid at their original URLs.[source-1, source-2, source-3]

Prioritization and ownership

Priority should be a function of verified exposure, business consequence, exploit maturity, and the cost of delay. A queue sorted only by severity tends to hide the work that needs immediate coordination, while a queue sorted only by scanner freshness rewards noisy tools. The owner should see why the task is urgent, what evidence supports that urgency, which control is expected, and how closure will be judged. When that information is missing, the first assignment should be investigation, not remediation theater.[source-1, source-2, source-3]

Sources

  1. [source-1] OpenSSH sshd_config manual
  2. [source-2] OpenSSH Server
  3. [source-3] Security Configuration Assessment

Related analysis