Multi-Factor Authentication and Bastion Hosts
You'll learn how to layer SSH authentication with a second factor and funnel administrative access through a hardened single point of entry.
Multi-factor authentication (MFA) for SSH adds a second proof of identity beyond your SSH key or password—typically a time-based one-time password (TOTP) generated by your phone. A bastion host (also called a jump server) is a dedicated, heavily secured server through which all administrative access flows, creating a choke point where you can enforce logging, auditing, and access control.
Why Combine These?
SSH keys alone can be stolen or compromised. Adding MFA means an attacker needs both your private key and physical access to your authentication device. A bastion host centralizes this protection: instead of securing SSH on dozens of servers individually, you harden one entry point and force all connections through it.
Implementing SSH MFA with PAM
Linux uses PAM (Pluggable Authentication Modules) to stack authentication methods. Google Authenticator is a popular PAM module that generates TOTP codes:
# Install Google Authenticator PAM module
sudo apt install libpam-google-authenticator
# Each user runs this to generate their TOTP secret
google-authenticator
# Configure PAM to require both key and TOTP
# Add to /etc/pam.d/sshd:
auth required pam_google_authenticator.so
# Modify /etc/ssh/sshd_config:
ChallengeResponseAuthentication yes
AuthenticationMethods publickey,keyboard-interactive
Bastion Host Architecture
Users connect to the bastion first, then jump to internal servers. The bastion logs all sessions, enforces MFA, and restricts which internal hosts each user can reach:
# User connects to bastion with MFA
ssh -i mykey.pem user@bastion.example.com
# From bastion, jump to internal server
ssh internal-server.local
Key Takeaway: MFA adds device-based proof to SSH authentication, while bastion hosts create a single, auditable gateway that centralizes hardening and simplifies access control across your infrastructure.