How to Implement Two-Factor Authentication on Your Hosting Account and Server

Overview

Two-factor authentication (2FA) requires a second form of verification beyond your password — usually a time-based one-time code from an authenticator app on your phone. Even if someone steals or guesses your password, they can’t log in without that second factor.

For hosting accounts, 2FA matters more than most people realize. Control panels like cPanel and WHM are high-value targets because they sit in front of your files, databases, email, and DNS. A compromised cPanel account can wipe out an entire site in minutes. The same applies to root SSH access on a VPS or dedicated server.

This article walks through enabling 2FA on cPanel, WHM, SSH (Linux), and WordPress. Use the section that matches your environment. If you’re on a Host & Tech managed plan, some of these steps may already be handled for you — check your welcome email or open a support ticket to confirm.

Prerequisites

  • An authenticator app installed on your phone: Google Authenticator, Authy, or 1Password all work. I’d recommend Authy if you want encrypted cloud backup of your TOTP secrets — losing your phone without a backup locks you out completely.
  • Access to your cPanel, WHM, or server root account (depending on which section applies to you)
  • For SSH 2FA: root or sudo access to your Linux server, running Ubuntu 20.04/22.04/24.04 or AlmaLinux/Rocky Linux 8/9
  • For WordPress 2FA: admin access to your WordPress dashboard and ability to install plugins
  • A backup of your recovery codes or a second device registered before you finish setup

Step-by-Step Instructions

1. Enable 2FA in cPanel

This covers accounts hosted on any standard cPanel server, including shared hosting and VPS plans with cPanel installed.

  1. Log in to cPanel (typically https://yourdomain.com:2083).
  2. In the search bar, type Two-Factor Authentication and click the result under the Security section.
  3. Click Set Up Two-Factor Authentication.
  4. Open your authenticator app, tap the + or Add Account button, then scan the QR code shown on screen.
  5. Enter the 6-digit code your app generates and click Configure Two-Factor Authentication.
  6. You’ll see a confirmation screen. Log out and log back in to verify it’s working before closing that window.

📝 Note: cPanel’s 2FA uses TOTP (Time-based One-Time Password, RFC 6238). Any standards-compliant authenticator app works — you’re not locked into any specific one.

⚠ Warning: cPanel does not provide recovery codes. If you lose access to your authenticator and get locked out, you’ll need to contact your hosting provider to disable 2FA at the server level. Keep a note of the manual setup key (shown below the QR code) somewhere safe — you can re-add the account to a new app with it.

2. Enable 2FA in WHM (for resellers and server admins)

WHM controls the entire server, so this one is non-negotiable if you manage multiple accounts.

  1. Log in to WHM at https://yourdomain.com:2087.
  2. In the left sidebar search, type Two-Factor Authentication and open it under Security Center.
  3. Click Manage My Two-Factor Authentication.
  4. Scan the QR code with your authenticator app, enter the generated code, and click Save.
  5. To require 2FA for all accounts on the server, return to the Two-Factor Authentication page and toggle Two-Factor Authentication Policy to enabled.

📝 Note: Enforcing the policy server-wide means accounts without 2FA configured will be prompted to set it up on next login. Users can’t skip it. This is worth doing on any server with more than one cPanel account.

3. Enable 2FA for SSH on a Linux VPS or Dedicated Server

This applies to any Linux server where you log in via SSH with a password or want an additional layer on top of SSH keys. If you’re on a Host & Tech Dedicated Server, this is especially relevant — root SSH access to a bare-metal machine is the highest-risk entry point you have.

  1. Log in to your server as root or a sudo user.

    ssh user@your-server-ip
  2. Install the Google Authenticator PAM module:

    # Ubuntu/Debian
    apt install libpam-google-authenticator -y
    
    # AlmaLinux/Rocky Linux/CentOS
    dnf install google-authenticator pam -y
  3. Run the setup as the user you want to protect (run this as that user, not root):

    google-authenticator

    Answer y to time-based tokens, then scan the QR code with your app. Save the emergency scratch codes somewhere offline — these are your only fallback if you lose your phone.

  4. Edit the PAM SSH configuration:

    nano /etc/pam.d/sshd

    Add this line at the top of the file, above any existing @include lines:

    auth required pam_google_authenticator.so
  5. Edit the SSH daemon config:

    nano /etc/ssh/sshd_config

    Find and set these two directives (or add them if missing):

    ChallengeResponseAuthentication yes
    UsePAM yes

    On Ubuntu 22.04 and newer, ChallengeResponseAuthentication has been renamed to KbdInteractiveAuthentication — set both if you’re unsure which version you’re running.

  6. Restart SSH — but do not close your current session yet:

    systemctl restart sshd
  7. Open a second terminal and test the login before closing your existing session. You should be prompted for your password and then a verification code.

⚠ Warning: If you restart SSH and immediately close your session without testing, and something is misconfigured, you can lock yourself out of the server entirely. Always keep your original session open while testing from a second terminal. On a dedicated server without IPMI/KVM access, this mistake is genuinely painful to recover from.

4. Enable 2FA on WordPress

WordPress doesn’t have built-in 2FA, so you’ll need a plugin. For most setups, WP 2FA (by Melapress) or Two Factor (the plugin by Plugin Contributors, hosted at wordpress.org/plugins/two-factor) both work reliably and don’t require paid tiers for basic TOTP.

  1. In your WordPress admin, go to Plugins > Add New Plugin.
  2. Search for WP 2FA, install, and activate it.
  3. The setup wizard launches automatically. Choose One-time code (TOTP) as your method.
  4. Scan the QR code with your authenticator app and enter the confirmation code.
  5. To enforce 2FA for all users (recommended for any multi-author site), go to WP 2FA > Policies and set the grace period to your preference. After the grace period, users without 2FA configured are blocked from accessing the dashboard.

📝 Note: If you’re on Host & Tech Managed WordPress Hosting, your environment is already hardened at the server level, but that doesn’t cover your WP admin login directly. Adding 2FA to the WordPress layer is still worth doing.

Common Issues & Troubleshooting

“Invalid verification code” every time you enter the correct code

This is almost always a clock sync issue. TOTP codes are time-based and expire every 30 seconds — if your phone’s clock is even 90 seconds off from the server’s clock, every code will fail. On Android, go to Settings > General Management > Date and Time and enable Automatic date and time. On iPhone it’s under Settings > General > Date & Time > Set Automatically. On the server side, check with timedatectl status and make sure NTP sync is active.

Locked out of cPanel after enabling 2FA

If you’ve lost your authenticator and can’t log in, a server admin with WHM access can disable 2FA for your account. In WHM, go to Security Center > Two-Factor Authentication, find the account, and click Remove. If you’re the root admin and have lost your own WHM 2FA, you’ll need SSH root access to run:

whmapi1 twofactorauth_remove_user_config user=root

SSH still not asking for a 2FA code after setup

The most common cause is that UsePAM yes or ChallengeResponseAuthentication yes isn’t actually active in /etc/ssh/sshd_config. Check for duplicate or conflicting directives, especially if your server has a /etc/ssh/sshd_config.d/ drop-in directory — files there can override the main config. Run sshd -T | grep -i challenge to see the effective value without restarting the daemon.

2FA codes work but then stop working after a server reboot

This usually means the PAM module line was added to the wrong file, or the ~/.google_authenticator file for the user doesn’t exist. The TOTP secret is stored per-user in ~/.google_authenticator. If this file is missing or has wrong permissions, PAM will fail silently or fall back. Check permissions with ls -la ~/.google_authenticator — it should be 600 (owner read/write only).

WordPress 2FA plugin breaks login after update

This error is annoyingly common when a plugin update conflicts with a caching layer or another security plugin. If you’re locked out, you can temporarily disable the 2FA plugin by renaming its folder via FTP or SSH: rename /wp-content/plugins/wp-2fa to /wp-content/plugins/wp-2fa-disabled. WordPress will auto-deactivate it on next page load. Then log in, check for conflicts, and rename the folder back once resolved.

FAQ

Frequently Asked Questions

What happens if I lose my phone and can't access my 2FA codes?

Your recovery options depend on where 2FA is set up. For cPanel, your hosting provider can disable it from WHM. For SSH, you’ll need a root terminal session (console/IPMI access) to remove the PAM configuration. This is exactly why you should save the manual setup key or emergency scratch codes during initial setup — treating them like a password you write down and store securely offline.

Does 2FA work with FTP or email clients that don't support it?

No — standard FTP and IMAP/SMTP protocols don’t support TOTP-based 2FA. If you’re using cPanel 2FA, it only protects the web-based control panel login. For FTP security, you should disable plain FTP entirely and use SFTP (SSH File Transfer Protocol) instead. For email, rely on strong unique passwords and consider IP allowlisting at the firewall level.

Is 2FA enough to fully secure my hosting account?

It’s one of the best single steps you can take, but it’s not a complete security plan on its own. 2FA protects the login — it doesn’t protect against vulnerable plugins, outdated software, weak file permissions, or server misconfigurations. Combine it with regular updates, malware scanning, and a firewall like CSF or Imunify360 for a more complete setup.

Can I use hardware security keys like YubiKey instead of an authenticator app?

Yes, but support varies by platform. cPanel and WHM don’t natively support FIDO2/WebAuthn hardware keys as of 2026 — they only support TOTP. For SSH, you can configure a YubiKey using the pam-u2f module, which is well-documented but more involved to set up. WordPress plugins like WP 2FA and Two Factor do support hardware keys as a 2FA method.

Should I enforce 2FA for all users on my WordPress site or server?

For WordPress: yes, at minimum for admin and editor roles. A compromised editor account can inject malicious content just as effectively as a compromised admin in many configurations. For server accounts: absolutely — any account with SSH or WHM access should have 2FA required, not optional. Optional 2FA gets skipped by the one user who then gets compromised.

SHARE THIS ARTICLE

Need help with your hosting?

Host & Tech provides 24/7 support for all VPS, dedicated, and shared hosting customers.

Scroll to Top