{"id":3480,"date":"2023-11-15T17:53:27","date_gmt":"2023-11-15T09:53:27","guid":{"rendered":"https:\/\/www.servergigabit.com\/guide\/?post_type=kb&#038;p=3480"},"modified":"2025-12-29T11:35:06","modified_gmt":"2025-12-29T03:35:06","slug":"how-to-activate-2fa-totp-on-a-vps","status":"publish","type":"kb","link":"https:\/\/www.servergigabit.com\/guide\/kb\/how-to-activate-2fa-totp-on-a-vps","title":{"rendered":"How to Activate 2FA\/TOTP on a VPS?"},"content":{"rendered":"<p><img fetchpriority=\"high\" decoding=\"async\" class=\"alignnone wp-image-3502\" src=\"https:\/\/www.servergigabit.com\/guide\/wp-content\/uploads\/2023\/11\/Modern-Digital-Marketing-Blog-Banner-300x169.jpeg\" alt=\"2FA\/TOTP\" width=\"617\" height=\"348\" srcset=\"https:\/\/www.servergigabit.com\/guide\/wp-content\/uploads\/2023\/11\/Modern-Digital-Marketing-Blog-Banner-300x169.jpeg 300w, https:\/\/www.servergigabit.com\/guide\/wp-content\/uploads\/2023\/11\/Modern-Digital-Marketing-Blog-Banner-1024x576.jpeg 1024w, https:\/\/www.servergigabit.com\/guide\/wp-content\/uploads\/2023\/11\/Modern-Digital-Marketing-Blog-Banner-768x432.jpeg 768w, https:\/\/www.servergigabit.com\/guide\/wp-content\/uploads\/2023\/11\/Modern-Digital-Marketing-Blog-Banner-1536x864.jpeg 1536w, https:\/\/www.servergigabit.com\/guide\/wp-content\/uploads\/2023\/11\/Modern-Digital-Marketing-Blog-Banner-2048x1152.jpeg 2048w, https:\/\/www.servergigabit.com\/guide\/wp-content\/uploads\/2023\/11\/Modern-Digital-Marketing-Blog-Banner-370x208.jpeg 370w, https:\/\/www.servergigabit.com\/guide\/wp-content\/uploads\/2023\/11\/Modern-Digital-Marketing-Blog-Banner-1230x692.jpeg 1230w, https:\/\/www.servergigabit.com\/guide\/wp-content\/uploads\/2023\/11\/Modern-Digital-Marketing-Blog-Banner-800x450.jpeg 800w, https:\/\/www.servergigabit.com\/guide\/wp-content\/uploads\/2023\/11\/Modern-Digital-Marketing-Blog-Banner-390x219.jpeg 390w\" sizes=\"(max-width: 617px) 100vw, 617px\" \/><\/p>\n<p>You can enable 2FA\/TOTP on a VPS by following the instructions in this guide. Let&#8217;s address the &#8220;what&#8221; and &#8220;why&#8221; first in order to lay the groundwork for a more secure and resilient virtual environment before getting into the &#8220;how.&#8221;<\/p>\n<h2 id=\"h-what-is-2fa-totp\" class=\"wp-block-heading\"><span id=\"what-is-2fatotp\" class=\"uag-toc__heading-anchor\"><\/span><strong>What Is 2FA\/TOTP?<\/strong><\/h2>\n<p><strong>Two-factor authentication (2FA)<\/strong> is a security procedure that goes above and beyond password verification. It usually involves two things: something you possess (like a mobile device) and something you know (like a password).<\/p>\n<p><strong>Time-based One-Time Passwords (TOTP)<\/strong> symbolize a particular type of 2FA in which a unique password is created on a regular basis, typically every 30 seconds, adding a fluid and time-sensitive component to the authentication procedure.<\/p>\n<h2 id=\"h-why-enable-2fa-totp-on-your-vps\" class=\"wp-block-heading\"><span id=\"why-enable-2fatotp-on-your-vps\" class=\"uag-toc__heading-anchor\"><\/span><strong>Why Do You Use 2FA\/TOTP On Your VPS?<\/strong><\/h2>\n<p>There are many possible risks in the digital world, and VPS servers are no different. On your VPS, turning on 2FA\/TOTP greatly improves the security posture of your server. By themselves, passwords are vulnerable to phishing and brute force attacks. You can strengthen your defenses against unauthorized access and lower the likelihood of data breaches and possible compromises by adding an additional layer of authentication.<\/p>\n<h2 id=\"h-prerequisites\" class=\"wp-block-heading\"><span id=\"prerequisites\" class=\"uag-toc__heading-anchor\"><\/span><strong>Prerequisites<\/strong><\/h2>\n<p>Make sure you have the following setup requirements before attempting to enable Two-Factor Authentication (2FA) with Time-based One-Time Passwords (TOTP) on your Virtual Private Server (VPS).<\/p>\n<h3 id=\"h-vps-access\" class=\"wp-block-heading\"><span id=\"vps-access\" class=\"uag-toc__heading-anchor\"><\/span><strong>1. VPS Access<\/strong><\/h3>\n<p>You need administrative access to your VPS and an SSH connection to your server in order to put security measures in place. Make sure you possess the authorization and rights required to modify configurations. If you are not the administrator, work with the individual or group in charge of managing the VPS.<\/p>\n<p>Not sure if you are the root \u2013 or what a \u201croot\u201d is? No problem! We got you covered with \u201c<a href=\"https:\/\/www.servergigabit.com\/guide\/kb\/superuser-accounts-sudo-root-a-practical-guide\" target=\"_blank\" rel=\"noreferrer noopener\">A Practical Guide to Superuser Accounts, sudo &amp; root<\/a>\u201d.<\/p>\n<h3 id=\"h-putty-a-reliable-ssh-client\" class=\"wp-block-heading\"><span id=\"putty-a-reliable-ssh-client\" class=\"uag-toc__heading-anchor\"><\/span><strong>2. PuTTY \u2013 A Reliable SSH Client<\/strong><\/h3>\n<p>A key protocol for securely accessing and managing your virtual private server (VPS) is Secure Shell (SSH). You can download <a href=\"https:\/\/www.chiark.greenend.org.uk\/~sgtatham\/putty\/latest.html\" target=\"_blank\" rel=\"noopener\">PuTTY<\/a>, a popular and trustworthy SSH client for Windows.It is important to ensure that your alternate SSH client is setup and prepared to establish a connection with your virtual private server (VPS).<\/p>\n<h2 id=\"h-setting-up-ssh-key-authentication\" class=\"wp-block-heading\"><span id=\"setting-up-ssh-key-authentication\" class=\"uag-toc__heading-anchor\"><\/span><strong>Setting Up SSH Key Authentication<\/strong><\/h2>\n<p>Secure your Virtual Private Server (VPS) by configuring SSH Key Authentication first. Please see our current guide on <a href=\"https:\/\/www.servergigabit.com\/guide\/kb\/how-to-use-ssh-keys-with-your-server-gigabits-server\">&#8220;How to Use SSH Keys with Your Server&#8221;<\/a> for a comprehensive walkthrough on configuring SSH Key Authentication.After setting up SSH Key Authentication, come back here to proceed with configuring Two-Factor Authentication (2FA) on your VPS using Time-based One-Time Passwords (TOTP).<\/p>\n<h2 id=\"h-installing-and-configuring-totp-on-your-vps\" class=\"wp-block-heading\"><span id=\"installing-and-configuring-totp-on-your-vps\" class=\"uag-toc__heading-anchor\"><\/span><strong>Installing and Configuring TOTP on Your VPS<\/strong><\/h2>\n<p>After implementing SSH Key Authentication, we can move forward with setting up and installing Time-based One-Time Passwords (TOTP) to enhance security on your VPS.<\/p>\n<h3 id=\"h-installing-required-packages-to-enable-totp\" class=\"wp-block-heading\"><span id=\"installing-required-packages-to-enable-totp\" class=\"uag-toc__heading-anchor\"><\/span><strong>Installing Required Packages to Enable TOTP<\/strong><\/h3>\n<p>Installing the required packages to enable TOTP should come first. Depending on the operating system of your VPS, the precise commands might change. For instructions, consult the package manager documentation for your system.<\/p>\n<p><strong>Example commands for a Debian-based system:\u00a0<\/strong><\/p>\n<pre class=\"wp-block-code\"><code>sudo apt-get update<\/code><\/pre>\n<pre class=\"wp-block-code\"><code>sudo apt-get install libpam-google-authenticator<\/code><\/pre>\n<h3 id=\"h-configuring-totp-for-ssh\" class=\"wp-block-heading\"><span id=\"configuring-totp-for-ssh\" class=\"uag-toc__heading-anchor\"><\/span><strong>Configuring TOTP for SSH<\/strong><\/h3>\n<p>Once the required packages are installed, configure TOTP for SSH.<\/p>\n<p>Edit the SSH daemon configuration file, usually located at <em>`\/etc\/ssh\/sshd_config`.<\/em><\/p>\n<p><strong>Ensure the following lines are present:\u00a0<\/strong><\/p>\n<pre class=\"wp-block-code\"><code>ChallengeResponseAuthentication yes\r\nAuthenticationMethods publickey,keyboard-interactive<\/code><\/pre>\n<p><strong>Save the changes and restart the SSH service:\u00a0<\/strong><\/p>\n<pre class=\"wp-block-code\"><code>sudo service ssh restart<\/code><\/pre>\n<h3 id=\"h-securing-your-ssh-configuration\" class=\"wp-block-heading\"><span id=\"securing-your-ssh-configuration\" class=\"uag-toc__heading-anchor\"><\/span><strong>Securing Your SSH Configuration<\/strong><\/h3>\n<p>To enhance security, disable password authentication for SSH.<\/p>\n<p><strong>Open the SSH configuration file again and set:\u00a0<\/strong><\/p>\n<pre class=\"wp-block-code\"><code>PasswordAuthentication no<\/code><\/pre>\n<p><strong>Restart the SSH service to apply the changes.\u00a0<\/strong><\/p>\n<pre class=\"wp-block-code\"><code>sudo service ssh restart<\/code><\/pre>\n<h2 id=\"h-setting-up-totp-on-your-mobile-device\" class=\"wp-block-heading\"><span id=\"setting-up-totp-on-your-mobile-device\" class=\"uag-toc__heading-anchor\"><\/span><strong>Setting Up TOTP on Your Mobile Device<\/strong><\/h2>\n<p>Now, let us configure the Time-based One-Time Passwords (TOTP) on your mobile device. This step ensures a seamless and secure authentication process for accessing your Virtual Private Server (VPS).<\/p>\n<h3 id=\"h-installing-a-totp-authenticator-app\" class=\"wp-block-heading\"><span id=\"installing-a-totp-authenticator-app\" class=\"uag-toc__heading-anchor\"><\/span><strong>Installing a TOTP Authenticator App<\/strong><\/h3>\n<p>Begin by installing a TOTP Authenticator app on your mobile device. Google Authenticator is a popular choice, but alternatives like\u00a0<a href=\"https:\/\/authy.com\/\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">Authy<\/a>\u00a0or\u00a0<a href=\"https:\/\/www.microsoft.com\/en-us\/security\/mobile-authenticator-app\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">Microsoft Authenticator<\/a>\u00a0work just as well. Visit your device\u2019s app store:<\/p>\n<p><strong>\u00a0Apps for Android:\u00a0<\/strong><\/p>\n<ul>\n<li><a href=\"https:\/\/play.google.com\/store\/apps\/details?id=com.google.android.apps.authenticator2\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">Google Authenticator<\/a><\/li>\n<li><a href=\"https:\/\/play.google.com\/store\/apps\/details?id=com.azure.authenticator&amp;hl=de&amp;gl=US\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">Microsoft Authenticator<\/a><\/li>\n<li><a href=\"https:\/\/play.google.com\/store\/apps\/details?id=com.authy.authy&amp;hl=de&amp;gl=US\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">Authy<\/a><\/li>\n<\/ul>\n<p><strong>Apps for iOS:\u00a0<\/strong><\/p>\n<ul>\n<li><a href=\"https:\/\/apps.apple.com\/us\/app\/google-authenticator\/id388497605\" target=\"_blank\" rel=\"noreferrer noopener\">Google Authenticator<\/a><\/li>\n<li><a href=\"https:\/\/apps.apple.com\/us\/app\/microsoft-authenticator\/id983156458\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">Microsoft Authenticator<\/a><\/li>\n<li><a href=\"https:\/\/apps.apple.com\/de\/app\/twilio-authy\/id494168017\" target=\"_blank\" rel=\"noreferrer noopener nofollow\">Authy<\/a><\/li>\n<\/ul>\n<p>Download and install the app.<\/p>\n<h3 id=\"h-adding-your-vps-to-the-authenticator-app\" class=\"wp-block-heading\"><span id=\"adding-your-vps-to-the-authenticator-app\" class=\"uag-toc__heading-anchor\"><\/span><strong>Adding Your VPS to the Authenticator App<\/strong><\/h3>\n<p>1. Open the TOTP Authenticator app.<\/p>\n<p>2. Tap on the option to add a new account or scan a barcode.<\/p>\n<p>3. On your VPS, run the following command to generate a QR code for the TOTP setup:<\/p>\n<pre class=\"wp-block-code\"><code>google-authenticator\u00a0<\/code><span id=\"setting-up-totp-on-your-mobile-device\" class=\"uag-toc__heading-anchor\"><\/span><\/pre>\n<p>4. Scan the QR code with your TOTP Authenticator app or manually enter the provided key.<\/p>\n<h3 id=\"h-generating-and-saving-backup-codes\" class=\"wp-block-heading\"><span id=\"generating-and-saving-backup-codes\" class=\"uag-toc__heading-anchor\"><\/span><strong>Generating and Saving Backup Codes<\/strong><\/h3>\n<p>Ensure you create and store backup codes as a precaution. In the unlikely event that you misplace your mobile device, these codes serve as a backup. A backup code generation prompt will appear during step 3 of the setup process. Keep these codes safe somewhere, like a physical backup or a password manager.<\/p>\n<p>Once you&#8217;ve configured TOTP on your phone, your VPS will only allow access to users who can authenticate with their SSH keys and a time-sensitive code from your authenticator app. This greatly increases server security.<\/p>\n<h3 id=\"h-testing-totp-authentication\" class=\"wp-block-heading\"><span id=\"testing-totp-authentication\" class=\"uag-toc__heading-anchor\"><\/span><strong>Testing TOTP Authentication<\/strong><\/h3>\n<p>It is especially crucial to verify the efficacy of TOTP authentication by testing it before finishing the setup. When you try to SSH into your virtual private server (VPS), you should be asked for your SSH key and the TOTP that your authenticator app produced.<\/p>\n<pre class=\"wp-block-code\"><code>ssh your_username@your_vps_ip\u00a0<\/code><\/pre>\n<p>If successful, you have successfully configured Time-based One-Time Passwords on your VPS.<\/p>\n<p>To complete the implementation and further secure your server, move on to the following steps.<\/p>\n<h2 id=\"h-enforcing-2fa-totp\" class=\"wp-block-heading\"><span id=\"enforcing-2fatotp\" class=\"uag-toc__heading-anchor\"><\/span><strong>Enforcing 2FA\/TOTP<\/strong><\/h2>\n<p>After setting up Time-based One-Time Passwords (TOTP), it&#8217;s time to make sure your VPS has Two-Factor Authentication (2FA) enabled. This makes sure that in order to access your server, you need to have both the dynamic TOTP that your mobile device generates and the SSH key authentication.<\/p>\n<h3 id=\"h-modifying-ssh-configuration\" class=\"wp-block-heading\"><span id=\"modifying-ssh-configuration\" class=\"uag-toc__heading-anchor\"><\/span><strong>Modifying SSH Configuration\u00a0<\/strong><\/h3>\n<p>Open your SSH configuration file, typically located at `\/etc\/ssh\/sshd_config`.<\/p>\n<p><strong>Make sure the following settings are configured:\u00a0<\/strong><\/p>\n<pre class=\"wp-block-code\"><code>ChallengeResponseAuthentication yes\r\nAuthenticationMethods publickey,keyboard-interactive\r\nPasswordAuthentication no<\/code><\/pre>\n<p><strong>Save the changes and restart the SSH service:\u00a0<\/strong><\/p>\n<pre class=\"wp-block-code\"><code>sudo service ssh restart<\/code><\/pre>\n<p>These settings ensure that SSH requires both public key authentication and the TOTP challenge.<\/p>\n<h3 id=\"h-disabling-password-authentication\" class=\"wp-block-heading\"><span id=\"disabling-password-authentication\" class=\"uag-toc__heading-anchor\"><\/span><strong>Disabling Password Authentication<\/strong><\/h3>\n<p>To strengthen security further, disable password authentication entirely.<\/p>\n<p><strong>Confirm that the following line is present in your SSH configuration file:\u00a0<\/strong><\/p>\n<pre class=\"wp-block-code\"><code>PasswordAuthentication no\u00a0<\/code><\/pre>\n<p><strong>Again, restart the SSH service to apply the changes.\u00a0<\/strong><\/p>\n<pre class=\"wp-block-code\"><code>sudo service ssh restart\u00a0<\/code><\/pre>\n<h3 id=\"h-adjusting-security-group-firewall-rules\" class=\"wp-block-heading\"><span id=\"adjusting-security-groupfirewall-rules\" class=\"uag-toc__heading-anchor\"><\/span><strong>Adjusting Security Group\/Firewall Rules\u00a0<\/strong><\/h3>\n<p>Make sure the required ports for SSH\u2014typically port 22\u2014are open if your VPS is protected by a firewall or security group. Furthermore, make sure that traffic for the selected TOTP port\u2014typically UDP port 123\u2014is permitted by the security group or firewall. As necessary, modify these rules to conform to the unique configuration of your server.<\/p>\n<p>After making these changes, your VPS is now requiring Time-based One-Time Passwords for Two-Factor Authentication, greatly strengthening the security posture of your server. Test access using the SSH key and the TOTP specifications to make sure the authentication process is successful.<\/p>\n<h2 id=\"h-conclusion\" class=\"wp-block-heading\"><span id=\"conclusion\" class=\"uag-toc__heading-anchor\"><\/span><strong>Conclusion<\/strong><\/h2>\n<p>Now that we&#8217;ve covered how to enable Two-Factor Authentication (2FA) on your Virtual Private Server (VPS) using Time-based One-Time Passwords (TOTP), let&#8217;s review the advantages and discuss some last ideas for boosting server security.<\/p>\n<h3 id=\"h-recap-of-the-benefits-of-enabling-2fa-totp\" class=\"wp-block-heading\"><span id=\"recap-of-the-benefits-of-enabling-2fatotp\" class=\"uag-toc__heading-anchor\"><\/span><strong>Recap of the Benefits of Enabling 2FA\/TOTP\u00a0<\/strong><\/h3>\n<p>Your VPS will be well-defended against potential security threats and unauthorised access if you enable 2FA\/TOTP. A multi-layered security approach has been built by fusing the dynamic feature of TOTP with SSH key authentication. The advantages consist of:<\/p>\n<ul>\n<li><strong>Enhanced Security:<\/strong>\u00a0Two layers of authentication significantly reduce the risk of unauthorized access, even if one factor is compromised.<\/li>\n<li><strong>Protection Against Brute Force Attacks:<\/strong>\u00a0The dynamic nature of TOTP codes makes brute force attacks more challenging to execute successfully.<\/li>\n<li><strong>Securing Sensitive Data:<\/strong>\u00a0If your VPS handles sensitive data or critical applications, 2FA\/TOTP adds an extra shield, ensuring the integrity and confidentiality of your information.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>You can enable 2FA\/TOTP on a VPS by following the instructions in this guide. Let&#8217;s address the &#8220;what&#8221; and &#8220;why&#8221; first in order to lay the groundwork for a more secure and resilient virtual environment before getting into the &#8220;how.&#8221; What Is 2FA\/TOTP? Two-factor authentication (2FA) is a security procedure that goes above and beyond password verification. It usually involves&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"kbtopic":[1099],"kbtag":[1243,1233],"class_list":["post-3480","kb","type-kb","status-publish","hentry","kbtopic-tutorials","kbtag-2fa-totp","kbtag-vps"],"_links":{"self":[{"href":"https:\/\/www.servergigabit.com\/guide\/wp-json\/wp\/v2\/kb\/3480","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.servergigabit.com\/guide\/wp-json\/wp\/v2\/kb"}],"about":[{"href":"https:\/\/www.servergigabit.com\/guide\/wp-json\/wp\/v2\/types\/kb"}],"author":[{"embeddable":true,"href":"https:\/\/www.servergigabit.com\/guide\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.servergigabit.com\/guide\/wp-json\/wp\/v2\/comments?post=3480"}],"version-history":[{"count":12,"href":"https:\/\/www.servergigabit.com\/guide\/wp-json\/wp\/v2\/kb\/3480\/revisions"}],"predecessor-version":[{"id":4392,"href":"https:\/\/www.servergigabit.com\/guide\/wp-json\/wp\/v2\/kb\/3480\/revisions\/4392"}],"wp:attachment":[{"href":"https:\/\/www.servergigabit.com\/guide\/wp-json\/wp\/v2\/media?parent=3480"}],"wp:term":[{"taxonomy":"kbtopic","embeddable":true,"href":"https:\/\/www.servergigabit.com\/guide\/wp-json\/wp\/v2\/kbtopic?post=3480"},{"taxonomy":"kbtag","embeddable":true,"href":"https:\/\/www.servergigabit.com\/guide\/wp-json\/wp\/v2\/kbtag?post=3480"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}