Published: | Last reviewed:
Harden a Linux bastion host by putting the second factor inside the SSH key: require a FIDO2 hardware key with PIN verification, accept only security-key algorithms, and give most people relay-only accounts that cannot open a shell. Then turn off agent forwarding, run sudo with a pseudo-terminal and recorded output, and load keyed audit rules that end with the lock option. PAM stays in the picture for account and session rules, not for proving a token is present.
Six settings do most of the work:
PubkeyAuthOptions verify-requiredmakes sshd insist on a PIN for FIDO keys [2].- Limiting
PubkeyAcceptedAlgorithmsto the two sk types keeps software-only keys out [2]. AllowAgentForwarding noworks best when most accounts have no shell [2].MaxSessions 0plus aPermitOpenlist turns an account into a relay for named targets [2].- sudo
log_outputwithsudoreplayrecords elevated sessions [4]. - Keyed audit rules that end in
-e 2make rule changes need a reboot [3].
Figure 1 shows the Linux bastion host this article hardens: one internet-facing SSH server between an administrator and the private systems behind it.
What the primary documentation establishes for a bastion host is narrower than most hardening checklists suggest. The OpenSSH 8.2 release notes introduced the ecdsa-sk and ed25519-sk key types, which tie a login to a FIDO token that must be attached when the key is used [1]. The sshd_config manual describes the PubkeyAuthOptions setting, where verify-required demands that the signature attest user verification such as a PIN, and it warns that turning off agent forwarding does not improve security while users still have shell access [2]. The sudo project's default sudoers template documents log_output together with sudoreplay for playing back logged sessions [4]. The Linux Audit manuals describe locking the audit configuration with the enabled flag set to 2, after which changes require a reboot [3]. Those documented behaviors are the spine of the baseline below, and the directive names in it were checked against those manuals.
What Does a Linux Bastion Host Need to Protect?
In this article, a bastion host is a Linux server that accepts administrator SSH sessions from outside and relays them to private systems. Because it faces the internet while holding a path into everything behind it, anyone who gets a shell there inherits that reach. Hardening therefore comes down to two questions: who gets in, and what each session is allowed to touch.
A Linux bastion host has three layers an attacker meets in order: the login method, whatever sshd lets a session forward, and the privileges reachable through sudo. This article covers those layers plus the audit trail they leave. For the operating system underneath, the Linux server hardening baseline guide covers the CIS and NIST material.
Evidence labels matter here. Directive names and documented behavior come from the five sources listed at the end, and design opinions are marked as mine. I did not run these configurations on a lab host for this article, so read the snippets as reviewed starting points rather than a tested build.
- Covered: FIDO2 SSH keys, forwarding limits, PAM's role, sudo, auditd.
- Not covered: kernel and filesystem baselines, firewall rules, patch levels.
Why Put the Second Factor in the SSH Key Instead of PAM?
A Linux bastion host can enforce a FIDO2 security key inside the SSH handshake, so the token stays with the administrator and the server never needs a USB device attached. The server can demand both a touch and a PIN on every login. PAM modules still matter for account and session rules, but they are a weaker fit for proving that a physical key is present.
OpenSSH 8.2 added the ecdsa-sk and ed25519-sk key types, and the release notes say the token must be attached whenever the key is used [1]. In practice the token is read on the administrator's machine, which is exactly what a bastion host wants. Teams already moving toward phishing-resistant MFA with FIDO2 will recognize the hardware; this is the SSH-side version of the same idea.
A hardware key stops a stolen file from becoming a stolen login.
- Each administrator generates an sk key pair on the client, ideally for two tokens.
- The public halves go into each account's authorized keys on the bastion host.
- sshd enforces the key type and the PIN on the server side.
On the client, key generation looks like the block below. I did not confirm from the sources which release added the verify-required generation option, so check ssh-keygen(1) on your client; the server setting further down enforces the PIN regardless.
# Client side, with the token plugged in
ssh-keygen -t ed25519-sk -O verify-required -f ~/.ssh/id_bastion_sk
# If the token has no Ed25519 support, use the type every FIDO token must implement
ssh-keygen -t ecdsa-sk -O verify-required -f ~/.ssh/id_bastion_sk
On the server, sshd uses the first value it obtains for each keyword, so place this drop-in early in the include order and keep the Match blocks at the end of the same file [2]. Figure 2 shows the order in which sshd applies these checks on the bastion host.
# /etc/ssh/sshd_config.d/10-bastion.conf
PermitRootLogin no
PasswordAuthentication no
KbdInteractiveAuthentication no
PubkeyAuthentication yes
PubkeyAcceptedAlgorithms sk-ssh-ed25519@openssh.com,sk-ecdsa-sha2-nistp256@openssh.com
PubkeyAuthOptions verify-required
AuthenticationMethods publickey
UsePAM yes
AllowGroups bastion-admins jump-only
MaxAuthTries 3
LoginGraceTime 30
# Detects dead connections, not idle administrators
ClientAliveInterval 60
ClientAliveCountMax 3
AllowAgentForwarding no
AllowStreamLocalForwarding no
AllowTcpForwarding no
X11Forwarding no
# Match blocks stay at the end of this file (see the next section)
The same manual documents a touch-required flag that stops authorized_keys entries from waiving the touch check, so read how your version's manual combines it with verify-required before relying on either [2].
A FIDO-backed OpenSSH key is split into two parts. According to the OpenSSH 8.2 release notes, a key handle sits in the private key file on disk, while a per-device private key unique to each token never leaves the hardware [1]. The hardware combines the two at authentication time, so the file copied from a stolen laptop should be useless to an attacker without the physical token [1]. Touch is required by default, and sshd can additionally require a PIN through verify-required [1] [2]. Resident keys are the exception worth watching: storing both halves on the token raises the odds that a stolen token is usable, so the release notes advise setting a PIN before creating any [1]. Every FIDO token must implement ecdsa-sk, while Ed25519 and resident-key support vary [1]. Enrolling two tokens per administrator is my own recommendation, not something the manuals require.
Should Agent Forwarding Be Disabled on a Bastion Host?
Yes, set AllowAgentForwarding to no on the bastion host, but understand what that setting does. The sshd_config manual states that disabling agent forwarding does not improve security unless users are also denied shell access, because they can install their own forwarders. So the setting only becomes meaningful when most accounts are limited to relaying connections and cannot open a shell on the bastion at all.
The manual's own caveat shapes the design [2]. A forwarded agent socket is a standing capability on the bastion for as long as the session lives, which is why the relay approach in Figure 3 is preferable. A hardware key softens that risk, since the release notes say tokens generally require a touch per operation, but it does not remove the reason to avoid forwarding [1].
A bastion host is only as strong as the most powerful thing one of its sessions can forward.
Split people into two groups. Members of bastion-admins keep shells for maintenance, while jump-only accounts get MaxSessions 0, which the manual says prevents all shell, login and subsystem sessions while still permitting forwarding [2]. Add PermitTTY no and a PermitOpen list of exact host and port pairs; sshd does no pattern matching or address lookups on those entries, so they must match what clients request [2].
Do not use DisableForwarding on the relay group, because the manual says it overrides all other forwarding options [2]. As far as I know, ssh -J depends on TCP forwarding, so test a real jump before rollout. The bastion host's relay group looks like this, restricting each jump-only account to named targets, which pairs naturally with network segmentation:
# Append to /etc/ssh/sshd_config.d/10-bastion.conf, after the global lines
Match Group jump-only
MaxSessions 0
PermitTTY no
AllowTcpForwarding local
# Replace with your real management addresses, exactly as clients type them
PermitOpen 10.20.0.11:22 10.20.0.12:22
What Is PAM Still Good For on a Key-Only Bastion?
On a key-only bastion host, UsePAM still runs PAM account and session processing for every login, so account checks and session setup keep working. A PAM authentication step can also be chained after the key through the AuthenticationMethods setting. That chain needs care, because a misconfigured PAM stack can lock out every user, including the ones trying to fix it.
In sshd_config, UsePAM yes enables PAM account and session processing for all authentication types, and the manual advises disabling either PasswordAuthentication or KbdInteractiveAuthentication because PAM keyboard-interactive usually plays the same role as a password [2]. The baseline above therefore turns both off and still keeps UsePAM yes.
If you do want a PAM step after the key, AuthenticationMethods can chain publickey with keyboard-interactive restricted to the pam device, and every listed method must also be enabled explicitly [2]. Yubico's pam-u2f module, whose README shows a required control line for second-factor use, is one candidate [5].
My reading of that README is that pam_u2f checks an authenticator the PAM stack itself can reach, and the README documents a manual mode intended for SSH sessions without FIDO support [5]. That makes it awkward on a remote bastion host, so I would keep it for console access and break-glass accounts unless you test the manual flow. I have not tested it.
# /etc/pam.d/sshd (README example: pam_u2f as a second factor)
# Primary authentication method(s) above this line.
auth required pam_u2f.so authfile=/etc/u2f_mappings cue
# sshd_config, only if you really want a PAM step after the key
KbdInteractiveAuthentication yes
AuthenticationMethods publickey,keyboard-interactive:pam
Two README warnings are worth repeating. An erroneous PAM configuration can lock out some or all users, so keep a separate root shell open while testing, and a mapping file stored in an encrypted home directory makes login impossible because that directory is only decrypted after login [5].
How Should sudo Be Locked Down on a Bastion Host?
Lock down sudo on a bastion host by editing sudoers only through visudo, running commands in a pseudo-terminal, and recording session output so every elevated command can be replayed later. Grant named commands to a named group instead of ALL, and treat any allowed program that can open an editor, pager or shell as equivalent to full root. Most of that comes straight from the sudo project's own default template.
The sudo project's default template opens by saying the file must be edited with visudo, to avoid syntax or permission errors that stop sudo from running [4]. Its comments also explain that running commands in a pseudo-terminal rather than the user's own terminal is meant to prevent command injection [4].
Output logging is opt-in. Enabling log_output stores sessions that sudoreplay can play back, and the template exempts sudoreplay itself from logging [4]. I left input logging off on purpose, since I would want to read the sudoers manual before storing keystrokes.
# Edit through visudo, never a plain text editor.
# Drop-in: /etc/sudoers.d/20-bastion
Defaults use_pty
Defaults log_output
Defaults!/usr/bin/sudoreplay !log_output
# Deliberately dull: two read-only audit tools, no ALL. Paths vary by distribution.
%bastion-admins ALL=(root) /usr/sbin/ausearch, /usr/sbin/aureport
The grant line is short on purpose. Broad grants are where bastion hosts go wrong, and a permitted program that can launch an editor, pager or shell hands out root under another name; that is my analysis rather than a quote from the sudo documentation. The audit rules in the next section watch these files so a change to them leaves a record.
Which auditd Rules Are Worth Loading on a Bastion Host?
An audit rule set for a bastion host should watch the files that define access, then record commands run by real login sessions. Use the syscall form of file rules with path or dir and perm, because the older watch syntax is deprecated and slower. Give every rule a key so investigators can search by meaning, and finish the file with the lock option so rule changes require a reboot.
The auditctl manual marks the -w watch form as deprecated because of poor system performance, and shows the syscall form with path, dir and perm as the replacement [3]. A key can be up to 31 bytes, and the audit.rules manual advises giving related rules a common key so investigations can filter by meaning [3].
Command execution records from the bastion host are also the raw material for the kind of hunting described in our guide to living-off-the-land activity in EDR telemetry. Figure 4 shows where each record goes on the bastion.
Put the lines below in the rules file your distribution loads at boot; auditctl(8) names /etc/audit/audit.rules [3]. The backlog and failure-mode values are my starting points, so size them for your host. The manuals say bi-arch systems need one rule per architecture, which is why execve appears twice.
## Bastion host audit rules
-D
-b 8192
-f 1
## Access-defining files
-a always,exit -F arch=b64 -F dir=/etc/ssh/ -F perm=wa -k bastion_sshd
-a always,exit -F arch=b64 -F path=/etc/sudoers -F perm=wa -k bastion_sudo
-a always,exit -F arch=b64 -F dir=/etc/sudoers.d/ -F perm=wa -k bastion_sudo
-a always,exit -F arch=b64 -F dir=/etc/pam.d/ -F perm=wa -k bastion_pam
## Commands run by real login sessions (drop the b32 line if the host has no 32 bit ABI)
-a always,exit -F arch=b64 -S execve -F auid>=1000 -F auid!=unset -k bastion_exec
-a always,exit -F arch=b32 -S execve -F auid>=1000 -F auid!=unset -k bastion_exec
## Lock the configuration. Must be the last line.
-e 2
Review works by key. The audit.rules manual shows aureport --start this-week --key --summary for a ranked list of triggering keys, and piping ausearch -k output into aureport to drill into files or users [3]. Ship the same records to a host the bastion's administrators cannot write to; that part is my recommendation.
A locked audit configuration turns quiet tampering into a reboot.
Two controls turn a hardened bastion host into an accountable one: recorded sudo sessions and a locked audit configuration. The sudo project's default template offers log_output as an opt-in setting, with sudoreplay for playback and an exemption for sudoreplay itself [4]. On the audit side, auditctl describes the -e 2 option as intended to be the last command in the rules file, after which any attempt to change the configuration is audited and denied [3]. The same manual warns that on many systems a default never,task rule makes every new process skip audit rule processing until 10-no-audit.rules is replaced [3]. Check auditctl -l after loading rules, because a rule set that never fires looks identical to a quiet system. Test the whole set on a spare host first, since a locked configuration cannot be corrected without a reboot.
What Can Go Wrong, and What Does This Baseline Not Prove?
Most failures when hardening a bastion host are lockouts rather than breaches: a PAM line that rejects everyone, or an audit lock applied before the rules were tested. This baseline also proves nothing about your hosts, because the settings come from vendor documentation and were not run in a lab for this article. Test each change on a spare machine with a second root session open.
The table below lists, for each control on the Linux bastion host, the setting involved and the most likely way it fails.
| Control | Setting | How it goes wrong |
|---|---|---|
| Hardware-backed login | sk key types, verify-required |
Ed25519 and resident-key support vary by token [1]; a lost token with no spare locks someone out (my analysis) |
| Relay-only accounts | MaxSessions 0, PermitOpen |
No pattern or address lookups, so entries must match client requests [2] |
| Agent forwarding | AllowAgentForwarding no |
Little protection if users still have shells [2] |
| PAM | UsePAM yes, optional pam_u2f |
Bad PAM config can lock out all users; mapping in an encrypted home blocks login [5] |
| sudo | use_pty, log_output |
Granted programs that spawn shells defeat the model (my analysis); edit only with visudo [4] |
| auditd | keyed rules, -e 2 last |
A default never,task rule can silence everything; the lock needs a reboot to change [3] |
A safe rollout order for the bastion host:
- Enroll two tokens per administrator and prove both log in while the old access path is still open.
- Apply the sshd drop-in and test from a second session before closing the first.
- Add the jump-only Match block and test a real jump to each listed target.
- Install the sudoers drop-in through visudo.
- Load the audit rules, confirm them with
auditctl -l, and add-e 2last.
The sshd_config text I used is an upstream OpenBSD manual revision dated September 2026 [2]. A distribution shipping an older OpenSSH may lack some options, so run man sshd_config on the bastion host itself before copying a directive.
What Should a Security Team Do With This Baseline?
Treat the bastion host configuration as reviewed code rather than a one-time project. Put the sshd, sudo and audit settings in version control, review changes the way you review application releases, and rehearse the loss of a hardware token before it happens. The goal is a bastion whose behavior you can explain, test and restore.
The bastion host also needs a place on the network map. Pair it with network segmentation so the PermitOpen list mirrors a real policy: the jump accounts reach a short list of management addresses and nothing else. If your wider design leans toward zero trust architecture, the bastion becomes one enforcement point among several, not the single gate.
Write the bastion host into your incident response plan as well. Decide in advance who can revoke a lost token, how the audit logs leave the host, and which sudo replay sessions get reviewed after an alarm. Patching OpenSSH and sudo belongs in your vulnerability management process, because both packages run on a machine that faces the internet.
Sources & References
- OpenSSH project. OpenSSH 8.2 release notes (released 2020-02-14).
- OpenSSH / OpenBSD. sshd_config(5), upstream manual page, revision 1.410 (September 2026), hosted on the Arch Linux manual pages site.
- Linux Audit project. auditctl(8) and audit.rules(7), man7.org.
- Sudo project. Default sudoers template (plugins/sudoers/sudoers.in), project mirror.
- Yubico. pam-u2f README, official repository.
A hardened jump box is only effective if it sits inside an isolated management VLAN—use our subnet calculator and network segmentation best practices to size your bastion CIDR blocks accurately.
- Standardize Your Fleet Baseline: Extend these jump-host controls across production workloads with our Linux server hardening baseline (CIS/NIST) and full security hardening guide.
- Protect SSH Keys & Audit Compromises: Enforce pre-commit scanning to keep SSH keys out of repositories, and keep our Linux forensics cheat sheet bookmarked for investigating suspicious bastion logins.

Leave a Comment (Authenticated Users)