Two-factor authentication (2FA)
Two-factor authentication (2FA) requires two different kinds of proof to log in, for example a private key or password plus a one-time code or a hardware security key. It is the two-step case of multifactor authentication (MFA), which CISA describes as a layered approach to securing online accounts and the data they contain.
Why it matters for servers
A password or an SSH key on its own can be guessed, phished or copied. A second factor means that one stolen secret is not enough. CISA states that users who enable MFA are significantly less likely to get hacked, and that any MFA is better than none, while phishing-resistant methods such as FIDO/WebAuthn are the standard to aim for.
Second factors for SSH
For SSH the practical options are a FIDO2 hardware-backed key (ed25519-sk) and a time-based one-time code through PAM. Both, and a safe rollout that avoids locking you out, are covered in our SSH two-factor authentication guide.
Which logins around a server need a second factor
CISA's multifactor authentication page groups factors into three kinds: something you know (a PIN or password), something you have (an authentication app or a phone) and something you are (a fingerprint or face scan). A real second factor comes from a different kind than the first, so a password followed by another memorised secret is still one kind. For organisations, CISA names remote access, email and billing systems as priorities, and that maps well to a VPS.
- SSH logins for administrators. Attackers probe this door constantly, and the SSH two-factor authentication guide covers how to add the factor.
- Your hosting account. A provider panel with a web console, rescue mode or a password reset is a separate way in that your sshd settings do not control. Protect it with a second factor too.
- Your email account. Password resets for the provider and for the domain usually arrive there, so whoever controls the mailbox can often take over everything else.
- Billing and DNS accounts. Losing them can mean losing the server or the domain without anyone touching SSH.
Secure these in that order of exposure, and choose a FIDO hardware key where the provider offers one, since CISA calls FIDO/WebAuthn the only widely available phishing-resistant method.
Check that it really works and plan for the bad day
Turning on a second factor is only half the job. Verify it, then prepare the recovery before you need it. On the server, confirm which methods are actually required:
sudo sshd -T | grep -iE '^(authenticationmethods|pubkeyauthentication|passwordauthentication|kbdinteractiveauthentication) '
The sshd_config manual says AuthenticationMethods lists the combinations a user must complete, and that the value any restores the default of accepting a single method. If the output still says any, no second factor is enforced, whatever the rest of your setup suggests. Then test from a brand-new connection with the key alone and confirm it is not enough.
Plan recovery in advance:
- Register a spare hardware key or keep the one-time scratch codes offline, stored apart from the laptop.
- Know how to reach your provider's console, and keep that account's second factor available too.
- Write down how a new administrator is enrolled and how a leaver is removed.
- Give automation its own restricted keys, because a deploy job cannot answer a prompt, and never share a person's hardware key.
Review the list of enrolled people on a schedule, the same way you review authorized_keys.
Related terms: Key-based authentication, SSH, sshd_config, Fail2ban, TOTP, FIDO2 and WebAuthn, PAM.
Frequently asked questions
Is 2FA the same as MFA?
Two-factor authentication is multifactor authentication with exactly two factors. MFA is the broader term for requiring two or more.
Is a one-time code from an app as strong as a hardware key?
No. A code can be typed into a fake prompt, while a FIDO key signs the login for the genuine site only, which CISA describes as phishing-resistant. A code is still much better than no second factor.
Can I lock myself out of my own server with 2FA?
Yes, if you change the SSH configuration carelessly. Keep an existing session open, validate the configuration, test from a new terminal and keep a provider console or rescue mode available.
Does a passphrase on my SSH key count as a second factor?
Not in a way the server can check. The passphrase protects the key file on your machine, but sshd cannot tell whether a normal key had one. A FIDO key with user verification required does enforce it, and the SSH two-factor guide covers that setup.
Which accounts should get a second factor first?
Start with the ones that control everything else: administrator SSH logins, the hosting provider account and the email account used for password resets. CISA lists remote access, email and billing systems as priorities for organisations.
Want to see where your own server stands?
Run the free, read-only server check, or open the Security Lab and watch the detect, contain, recover, verify loop in action.
Get your free server checkOpen the Security Lab