# Two-factor Authentication

## **Enable two-factor Authentication**

**Two-factor authentication (2FA)** adds an extra layer of security to your Ubuntu system by requiring two forms of identification before granting access. In addition to the usual username and password, 2FA requires an additional piece of information, such as a one-time password (OTP) generated by an authenticator app.

First of all, download the Google Authenticator app on your mobile device

<figure><img src="/files/rWrzF5k72uYeXmtGvnXF" alt=""><figcaption></figcaption></figure>

Here are some methods to enable 2FA on Ubuntu:&#x20;

### Install the Google Authenticator PAM plugin:

<pre><code><strong>sudo apt-get update -y
</strong></code></pre>

```
sudo apt-get install libpam-google-authenticator -y
```

Run the google-authenticator command as the user you want to log in (**not** as root):

```
sudo google-authenticator 
```

Follow the prompts to set up 2FA. You’ll need an authenticator app (e.g., Google Authenticator or Authy) on your mobile device to scan the QR code.

<figure><img src="/files/7YAX8OJml1qNkYIgOcdZ" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/a4EqkCy09pRwPc0G1C2O" alt=""><figcaption></figcaption></figure>

### Edit the pam.d file

Edit the **/etc/pam.d/sshd** file and add the following line at the end.

```
vi /etc/pam.d/sshd
```

**auth required pam\_google\_authenticator.so**

<figure><img src="/files/PbGjk7UBZyvrJJqDL3kr" alt=""><figcaption></figcaption></figure>

save the file and exit

Edit the **/etc/ssh/sshd\_config** file

```
vi /etc/ssh/sshd_config
```

**KbdInteractiveAuthentication no > Yes**&#x20;

<figure><img src="/files/CAG5ByoQYXoVg3NZx8QN" alt=""><figcaption></figcaption></figure>

### Restart the service

Edited both the file restart service

```
systemctl restart sshd.service
```

Open the Command prompt to access the server&#x20;

**ssh user\@IP\_Addresss**

Enter the password and the verification code from your Google Authenticator app on your mobile device.

<figure><img src="/files/SAK6NrDeD4SICu8ef2Zc" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.neevcloud.com/neevcloud-guide/neevcloud-knowledgebase/two-factor-authentication.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
