What counts as a factor?
Factors fall into three families. Something you know: a password, a PIN or the answer to a question. Something you have: a phone running an authenticator app, a hardware security key, a smart card or a private key file. Something you are: a fingerprint or face scan, usually used to unlock a device rather than sent to a server. Real MFA combines factors from different families. A password plus a security question is still one factor twice, because both can be phished or guessed the same way. Authentication covers the wider process these factors plug into.
How do the common second factors compare?
| Method | How it works | Phishing resistant | Main weakness |
|---|---|---|---|
| SMS or voice code | A code sent to a phone number | No | SIM swaps and interception; better than nothing |
| Email code or link | A code sent to the mailbox | No | Only as strong as the mailbox account |
| TOTP app | A six-digit code computed from a shared secret and the time | No | Users can be tricked into typing it into a fake site |
| Push approval | An app asks the user to approve a login | Partly, with number matching | Fatigue attacks that spam prompts until someone taps yes |
| Security key or passkey (FIDO2/WebAuthn) | A key pair bound to the real site origin | Yes | Needs a backup key or recovery plan |
| Client certificate or SSH key | A private key held by the device | Yes | Key files must be protected and rotated |
Phishing resistance is the property that matters most today. A security key will not answer a fake domain, because the browser includes the real origin in what the key signs, so even a perfect copy of your login page gets nothing usable.
How does a TOTP code work?
When you enroll, the server and your app share a random secret, usually shown as a QR code. Every 30 seconds both sides compute an HMAC of the current time step with that secret and shorten it to six digits, following RFC 6238. The server accepts the current code and often one step either side to allow for clock drift. That is why a server with the wrong time rejects valid codes; keep chronyd or systemd-timesyncd running and check with timedatectl show -p NTPSynchronized. Hashing explains the HMAC underneath.
How do I add a second factor to SSH?
The strongest simple setup is an SSH key that lives on a hardware security key. OpenSSH 8.2 and later support ed25519-sk keys, which require the physical key to be present and touched for every login:
ssh-keygen -t ed25519-sk -O verify-required -C "ana@ops-laptop" -f ~/.ssh/id_ana_sk ssh-copy-id -i ~/.ssh/id_ana_sk.pub ana@203.0.113.140
If you prefer a key file plus a TOTP code, the pam_oath module adds a code prompt after the key is accepted. Secrets live in one root-only file, one line per user:
apt install -y libpam-oath oathtool printf 'HOTP/T30/6 ana - %s\n' "$(openssl rand -hex 20)" >> /etc/ssh/oath.users && chmod 600 /etc/ssh/oath.users sed -i '1i auth required pam_oath.so usersfile=/etc/ssh/oath.users window=1' /etc/pam.d/sshd printf 'KbdInteractiveAuthentication yes\nAuthenticationMethods publickey,keyboard-interactive\n' > /etc/ssh/sshd_config.d/40-mfa.conf sshd -t && systemctl reload ssh.service # syntax check first, then apply without dropping sessions
Give each user their secret in base32 form for the authenticator app, and keep a session open while testing; a user with no line in the file cannot finish a login once this is active. On Debian and Ubuntu the PAM file also includes common-auth, which may prompt for a password; comment out @include common-auth in /etc/pam.d/sshd if you want key plus code only. Harden SSH on Linux covers the other SSH settings.
How should web applications offer MFA?
- Offer passkeys or security keys first, TOTP second, and SMS only as a fallback.
- Issue one-time recovery codes at enrollment and store only their hashes.
- Ask for the factor again before sensitive actions such as changing the email, adding an API key or exporting data.
- Rate limit code attempts; six digits fall to brute force quickly without a cap.
- Never let support staff disable MFA on a phone call alone; that path is how many accounts are taken over.
What does MFA not stop?
Session theft after login, malware on the user's device, and real-time phishing proxies that relay codes to the real site. Passkeys block the last one; short session lifetimes and binding sessions to devices limit the first. MFA greatly reduces account takeover risk but works best alongside patching, least privilege and monitoring.
Where does MFA fit on a dedicated machine?
Everywhere people log in: SSH, admin panels you host, Git and CI tools, and the identity provider behind your other apps. An identity server such as Keycloak handles MFA for many apps at once and runs comfortably on the S1 (64 GB DDR4); a second instance on the S2 in another city adds resilience. ZTNA shows how that identity layer gates internal tools.
Machines for a Self-Hosted Identity Server
| Server | Processor | Cores / threads | Memory | Storage | Network | Per month | Smallest order |
|---|---|---|---|---|---|---|---|
| E1 | Intel Xeon E3-1240 v3 | 4 / 8 | 16 GB DDR3 | 2x 240 GB SSD | 2x 1 Gbps | $30.52 | $91.56 (3 months) |
| S1 | Intel Xeon E-2276G | 6 / 12 | 64 GB DDR4 | 1x 1 TB NVMe | 2x 10 Gbps | $53.32 | $53.32 (1 month) |
| S2 | Intel Xeon E-2356G | 6 / 12 | 64 GB DDR4 | 1x 1 TB NVMe | 2x 10 Gbps | $58.39 | $58.39 (1 month) |
Keep Reading
Authentication
How a system confirms that a user, device or service is who it claims to be, the main methods, and Linux logins.
OpenTwo-Factor Authentication
The most common form of MFA: a password plus one more proof, how to set it up well, and how to avoid getting locked out.
OpenHarden SSH on Linux
A practical hardening list for sshd on a fresh dedicated box: keys, users, rate limits, firewall scope and an outside audit.
OpenSSH keys
How SSH key pairs replace passwords, how to make an ed25519 key and how to have it placed on your machine at install time.
OpenFAQ
Quick Answers
A login that needs at least two different kinds of proof, such as a password plus a code from a device you hold.
Security keys and passkeys based on FIDO2, because they are tied to the real site and cannot be phished.
It is better than a password alone, but SIM swaps and interception make app codes or security keys the better choice.
Usually the clock on the server or phone is off. Keep time synchronized with NTP and allow one time step of drift.
Yes. Use ed25519-sk keys on a hardware security key, or combine an SSH key with a TOTP code through PAM.