How to Configure Amazon Linux SSH 2FA
You set up amazon linux ssh 2fa by pairing SSH key checks with a PAM time-based code module. The SSH daemon then asks for both a key and a six-digit code at login. Most platform teams add this extra check on every cloud server or bastion host. Still, once an engineer passes that login gate, broad OS roles still let them run any command. How amazon linux ssh 2fa works in practice Amazon Linux uses the OpenSSH server daemon and the Linux PAM framework to check user logins. To require two factor
SSH Access Management + End-to-End Encryption: the complete guide
Architecture patterns, implementation strategies, and security best practices. Delivered to your inbox.
You set up amazon linux ssh 2fa by pairing SSH key checks with a PAM time-based code module. The SSH daemon then asks for both a key and a six-digit code at login. Most platform teams add this extra check on every cloud server or bastion host. Still, once an engineer passes that login gate, broad OS roles still let them run any command.
How amazon linux ssh 2fa works in practice
Amazon Linux uses the OpenSSH server daemon and the Linux PAM framework to check user logins. To require two factors, admins turn on both public key checks and keyboard-interactive checks in the SSH service. The server checks the cryptographic key first during the initial connection phase.
After the SSH key passes, the SSH daemon hands the login flow over to the PAM stack. A time-based one-time password module in PAM prompts the user for a short code from their phone. Both checks must pass before the server opens a shell session for the user.
Some teams also use OpenSSH certificates instead of static public keys to cut down on key sprawl. A certificate authority key signs a user public key along with an identity name and principal names. This OpenSSH certificate format is much simpler than the X.509 format used in TLS connections.
Each user still needs to set up a shared secret file in their home directory on the host. When you run dozens of servers, syncing those secret files across every machine creates heavy toil. If an instance scales up from a base image, it might lack the user secret files.
Why host-level 2FA is only a partial control
Host-level two-factor checks do a great job of stopping stolen SSH keys from working alone. An attacker who grabs a private key from a laptop still hits the second code prompt. This setup meets basic compliance rules that ask for multi-factor checks on server logins.
Still, host-level login checks only decide who gets into the shell at the start of a session. They do not inspect or limit what commands the engineer runs after the shell opens. If five engineers share the default system user account, they all share the same OS permissions.
SSH Access Management + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Standard SSH logs record which key or user logged in, not the exact commands run inside sudo. When an engineer reads a local file or queries a service, raw sensitive values print to the terminal. Nothing in the PAM login flow rewrites matched fields like emails, phone numbers, card numbers, or national IDs.
Managing two-factor state across many cloud hosts also breaks down when people leave the team. You have to remove their keys and clear their two-factor secrets on every single server they touched. If you miss one host, that former team member might still log in if a key remains.
Moving from per-host setup to central session controls
Relying on local PAM files forces ops teams to treat every cloud server like a custom pet. When a phone breaks or gets lost, an admin must log in to reset the local secret file. That recovery process fails fast if all admins lose their second factor at the same time.
Tying SSH logins to your central identity provider removes the need for per-host secret files. Users prove who they are through their normal single sign-on flow before they open a server session. You also gain a clear way to link every action back to one specific person.
Check SSH commands and file transfers on the host
OpenSSH keys and certificates decide who can log into a Linux host. They do not check what a one-shot command or file transfer does once the session starts. With hoop.dev, you run an open-source SSH server with guardrails inline on the host. On every one-shot command or file transfer an AI agent or engineer runs against production, hoop.dev decides to pass, mask, block, or hold it for human review.
When a caller runs a one-shot command or moves a file, hoop.dev guardrails check the command or path before it runs, and hoop.dev data masking masks matched sensitive patterns in downloads and output. Interactive shells carry no guardrails because keystrokes have no statement boundary. Teams can turn interactive shells off and allow only commands and file tasks. The audit trail logs who connected and what was allowed or refused, without storing keystrokes or file bytes. See the source on GitHub.
Frequently asked questions
What happens if I lose my phone after setting up Amazon Linux SSH 2FA?
You cannot pass the PAM code check over SSH if you lose your code generator app. An admin must use an out-of-band cloud console session to reset your secret file on the server.
Does Amazon Linux SSH 2FA block automated scripts and CI jobs?
Yes, a global two-factor rule blocks automated tools that cannot type a six-digit code. Teams must add match blocks in the SSH server settings to skip the second factor for service accounts.
Can I use OpenSSH certificates alongside two-factor codes on Amazon Linux?
Yes, OpenSSH lets you require both a valid user certificate and a PAM code check at login. The server checks the certificate signature first and then prompts the user for their one-time code.
Related guides
In this post