For Ubuntu Server, the documented PAM-based SSH setup requires a public key first and a one-time code second. Before enabling it, verify key-based access, enroll every SSH user, and confirm you can recover through your VPS provider’s console. SSH two-factor authentication protects SSH logins; it does not secure every account or service on the VPS.
What SSH two-factor authentication protects
This guide configures a second factor for SSH access to the Linux guest operating system. In Ubuntu’s documented TOTP/HOTP flow, OpenSSH first checks a public key, then prompts for a one-time password through PAM and keyboard-interactive authentication. The documented configuration disables SSH password authentication.
This is separate from multi-factor authentication on your VPS provider account or access through its web console. It also does not automatically require a second factor for web applications, databases, or sudo. Configure those separately if you need them protected.
Prepare before changing SSH authentication
- Identify your Linux distribution and release. The commands and PAM arrangement below target Ubuntu Server; other distributions may package the module or structure PAM differently.
- Confirm you can log in over SSH now and have a separate sudo-capable administrator account. Vultr’s prerequisites also recommend an updated system, a firewall, and SSH-key access; see Vultr’s guide.
- Verify how to reach your provider’s out-of-band console or rescue environment. The recovery method varies by provider; do not assume console access has the same authentication requirements as SSH.
- Keep your existing privileged SSH session open while changing settings. Use a second terminal for the test login, and do not close the first session until the full key-plus-code flow works.
- List every user who needs SSH access and enroll each one before making the second factor mandatory. Ubuntu warns that users need their public-key access and 2FA secret configured before enforcement, or they may be unable to log in to finish setup.
Choose a second-factor method
PAM-backed TOTP or HOTP
Ubuntu documents the libpam-google-authenticator PAM module and a per-user setup command. Each user enrolls a secret in a compatible authenticator app. The resulting per-user file contains the shared secret, emergency passcodes, and configuration, so treat it as sensitive authentication material.
#1 Best Overall
- Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
- Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
- Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
- Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
- 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
Ubuntu generally prefers TOTP when the authenticator supports it. TOTP codes depend on both the server and authenticator having sufficiently aligned clocks. HOTP codes advance through a sequence; if codes are generated but the server does not advance in step, the two sides can get out of sync.
Hardware-backed U2F/FIDO
Ubuntu recommends hardware authentication devices that support U2F/FIDO for the strongest 2FA security. Its separate OpenSSH guide covers security-key types such as ecdsa-sk and ed25519-sk. This is a different setup path: it requires compatible OpenSSH support and a supported hardware device to be present for authentication. Consult Ubuntu’s U2F/FIDO documentation. Ubuntu’s TOTP guide says combining that method with its PAM TOTP/HOTP setup is not recommended because the combination has not been tested there.
| Method | Credential and requirements | Important failure or recovery consideration |
|---|---|---|
| PAM TOTP/HOTP | Per-user secret and one-time code; PAM module and SSH keyboard-interactive configuration. | TOTP depends on clock alignment; HOTP can desynchronize. Protect backup codes and secrets. |
| OpenSSH U2F/FIDO | Hardware security device and compatible OpenSSH security-key support. | The device must be available. Plan an alternate access or recovery route appropriate to your setup. |
Set up PAM-backed TOTP on Ubuntu Server
Use the current Ubuntu Server procedure for your release as the authority for exact PAM edits and service handling. The Ubuntu documentation is titled “Two factor authentication with TOTP/HOTP” and was last updated June 26, 2026.
Rank #2
- 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
- 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
- Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
- 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
- What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
1. Install the PAM module
On Ubuntu, update package metadata and install the module:
PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minutesudo apt update && sudo apt install libpam-google-authenticator
2. Enroll each SSH user
For each user, run the module’s setup command as that user, following its prompts and the current Ubuntu instructions. Scan the displayed QR code or enter the secret into a compatible authenticator. Store emergency passcodes securely and keep the generated secret file private. Do not store an unencrypted copy of the shared secret in a notes-sync service.
Do not enable mandatory OTP for an account until that user has a working SSH key and has completed enrollment. Review the current prompts rather than assuming an older guide’s defaults are unchanged. Ubuntu’s older tutorial advises rate limiting and preventing multiple uses of a token; treat those as version-sensitive setup choices, not universal defaults.
Rank #3
- Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
- Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
- Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
- Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
- What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
3. Configure PAM for SSH
Follow Ubuntu’s current procedure to make the SSH PAM stack invoke the OTP module in /etc/pam.d/sshd. Ubuntu’s older tutorial shows the line auth required pam_google_authenticator.so, but its example uses legacy configuration names; do not substitute it blindly for the current release’s documented PAM setup.
4. Configure the SSH daemon
Ubuntu’s documented SSH configuration excerpt is:
Free tools Windows power users keep installed
One-click scans. No signup required.
KbdInteractiveAuthentication yes
PasswordAuthentication no
AuthenticationMethods publickey,keyboard-interactive
Ubuntu 20.04 LTS and earlier use ChallengeResponseAuthentication yes instead of KbdInteractiveAuthentication yes in this configuration. Check the daemon’s main file and included configuration files for existing or conflicting directives before editing; duplicate settings can produce unexpected effective values.
Rank #4
- Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
- Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
- Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
- Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
- Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
5. Check the PAM authentication path
Keyboard-interactive provides text prompts and can invoke PAM. That does not mean it is limited to OTP: PAM may also offer password authentication. Mozilla’s OpenSSH guidance warns that PasswordAuthentication no alone does not prove password authentication is impossible if PAM still enables it. Inspect /etc/pam.d/sshd and any included stacks to confirm the actual path requires the intended factors and has no unintended password fallback.
PAM stacks are distribution-specific. Do not replace a PAM file with a generic snippet from another distribution. If you are not on the Ubuntu release covered by the instructions, use your vendor’s current documentation and understand the included PAM rules before changing authentication.
6. Apply and test the change
Apply the SSH configuration using the restart or reload procedure documented for your Ubuntu release. Keep your current session open, then connect from a second terminal. Confirm the server accepts the intended key and prompts for the OTP, and verify that the login completes only with both. If it fails, use the open session or provider recovery console rather than closing your last working administrative path.
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Best Value
- 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
- Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
- Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
- HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
- What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
Plan recovery before relying on MFA
Decide what happens if a phone is lost, damaged, replaced, or unavailable. Ubuntu lists authenticator backup or sync, securely stored backup codes, multiple enrolled TOTP devices, and another authentication path for rerunning setup as possible mitigations. Each backup can weaken the additional factor if an attacker obtains it, so protect it appropriately.
Separately verify your provider’s console or rescue procedure before enforcement. Vultr documents its web console as a way to recover from SSH lockout; your provider may work differently. Keep recovery material somewhere other than the VPS where practical, and ensure authorized administrators can reach it without relying on the device that may be lost.
Troubleshoot common login failures
- The SSH client never asks for a code: Confirm the effective daemon configuration enables keyboard-interactive authentication and requires
publickey,keyboard-interactive. Check included SSH configuration files and the PAM SSH stack. - The key works but the OTP is rejected: For TOTP, check that the server and authenticator clocks are aligned. For HOTP, codes generated without a matching server advance can desynchronize the sequence. Use your documented recovery path if correcting the cause does not restore access.
- A user cannot log in after enforcement: Verify that the user enrolled a secret and has a working public key before enforcement. Use an already-open administrator session or provider console to correct the account configuration.
- A password prompt still appears or a password works: Inspect PAM and its included stacks. Disabling
PasswordAuthenticationdoes not by itself rule out password authentication through keyboard-interactive and PAM. - Configuration changes lock out new sessions: Do not close the known-good session before testing. If all SSH access is lost, use the provider’s verified console or rescue process.
Keep the rest of the VPS secure
SSH MFA is one layer, not a complete VPS security plan. Maintain key-based access, keep the system updated, limit network exposure with a firewall, protect provider-account access, and review which users have administrative privileges. If you intentionally want MFA for sudo, configure and test that separately; this SSH procedure does not enable it.
Or let it run in the cloud
For a different task—keeping a pre-recorded YouTube live stream running—StreamNeo is a cloud service from Yorker Media, not a VPS security tool. Upload a recording or build a playlist, add your YouTube stream key, and go live. Nothing has to stay on at home; it streams uploads as made, up to 4K 60fps at one flat price per slot, with automatic recovery if YouTube drops the stream. The first day is free with no card. Monthly billing is $9.99 per month. See StreamNeo or start the free day.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

