How to Configure Rocky Linux SSH 2FA

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up rocky linux ssh 2fa by pairing SSH keys with a PAM code module. The server then checks both factors before it lets a user log in. Most teams start by turning on time-based codes on each server or bastion. This step blocks stolen keys from working on their own. Yet a valid login still gives broad shell power if local roles stay wide open. How rocky linux ssh 2fa works in practice OpenSSH on Rocky Linux works with the system PAM stack to check multiple login factors. First, the SSH d

SSH Access Management + End-to-End Encryption: the complete guide

Architecture patterns, implementation strategies, and security best practices. Delivered to your inbox.

Free white paper. No spam. Unsubscribe anytime.

You set up rocky linux ssh 2fa by pairing SSH keys with a PAM code module. The server then checks both factors before it lets a user log in. Most teams start by turning on time-based codes on each server or bastion. This step blocks stolen keys from working on their own. Yet a valid login still gives broad shell power if local roles stay wide open.

How rocky linux ssh 2fa works in practice

OpenSSH on Rocky Linux works with the system PAM stack to check multiple login factors. First, the SSH daemon checks the user public key or a signed OpenSSH certificate. OpenSSH certificates hold a public key, identity details, principal names, and options signed by a CA key. These certificates use a much simpler format than standard TLS certificates.

After the key check passes, the SSH daemon hands the login flow to PAM. The PAM module asks the user for a one-time code from a phone app or hardware token. Each user must first register a secret seed on the host or in a central directory. When the user types the right code, PAM tells the SSH daemon to open the shell.

Teams must also set the SSH daemon to require both the key and keyboard input. If you miss a step in the daemon rules, SSH might accept just one factor. Admins must also guard against lockouts by keeping a root shell open during testing. If PAM fails or the system clock drifts, time-based codes will stop working right away.

What native two-factor login solves and what it leaves open

Adding a second factor stops attackers who steal a static private key from a laptop. A leaked key alone cannot open a shell on your Rocky Linux hosts anymore. Even if a user picks a weak key passphrase, the one-time code blocks remote entry. This setup works well for meeting basic login rules across small fleets.

Still, native two-factor checks only work at the moment the user logs in. Once the shell opens, neither PAM nor the SSH daemon inspects what the user runs. Every engineer who logs into a shared Linux account gets the same broad host rights. If three people share an admin user, the host logs cannot easily tell them apart.

SSH Access Management + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Managing secret seeds across dozens of Rocky Linux hosts also creates extra manual work. When someone loses a phone, an admin must reset their token on every single host. And when a contractor leaves the team, revoking local keys and seeds takes time. Also, shell commands can dump files containing customer emails, phone numbers, or card numbers directly to the screen. Login checks alone cannot rewrite those fields or block risky commands in flight.

Why teams pair OpenSSH certificates with strong login checks

Many teams replace static public keys with OpenSSH user certificates to cut down on key sprawl. An admin uses a CA key to sign a user public key with an identity and principal names. You can also set a validity window so the certificate expires on its own. If you do not set an expiry window, the certificate stays valid forever by default.

Even with short-lived certificates and two-factor prompts, the Linux shell remains an all-or-nothing session. A user who passes the login check can still run destructive commands or read raw files. Teams that need command-level control and clean audit trails must look beyond host-level PAM rules.

Add command and file guardrails to SSH access

Host firewalls and certificate principals control who opens an SSH session. Yet an allowed user or agent can still run a bad one-shot command or pull sensitive files over sftp. In practice, hoop.dev sits inline on the host as an open-source SSH server with guardrails that uses OpenSSH certificates. For every one-shot command or sftp task an agent or human runs in production, hoop.dev decides to pass, mask, block, or escalate it for review.

Using hoop.dev SSH controls, guardrails check one-shot commands, env variable names, and sftp or scp paths before they run. Port forwards default to deny unless the target is listed. Because interactive shells have no statement boundary and carry no guardrails, teams can turn them off so every command is checked and logged. Check out the MIT-licensed project on GitHub.

Frequently asked questions

What happens if the server clock drifts on Rocky Linux?

Time-based one-time codes depend on an accurate system clock on the host. If the Rocky Linux clock drifts too far, PAM will reject valid codes from users. Keep a network time service running on all servers so login codes stay in sync.

Can I require both an SSH key and a one-time code?

Yes, the OpenSSH daemon lets you chain multiple login methods in a set order. You tell the daemon to check the public key first and then run the PAM prompt. The server only opens the shell when the user passes both checks in the same login.

How do I avoid locking myself out while testing SSH 2FA?

Always keep an active root shell open in a separate terminal window before you reload SSH. Test the new login flow in a fresh window while keeping the original session alive. If the PAM rule or key check fails, you can fix the settings right away.

Save the open-source gateway.

hoop is MIT-licensed infrastructure for controlling how AI agents reach production data. Star hoophq/hoop so you can inspect it, deploy it, or share it when your team starts governing agent access.