# Command line disable Two Factor Authentication

**URL:** https://meta.discourse.org/t/command-line-disable-two-factor-authentication/121480
**Category:** Support
**Created:** [June 27, 2019, 9:54am UTC](https://meta.discourse.org/t/command-line-disable-two-factor-authentication/121480 "2019-06-27T09:54:06Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![thaidb](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/thaidb/32/68488_2.png) [@thaidb](https://meta.discourse.org/u/thaidb)
#### Post date: [June 27, 2019, 9:54am UTC](https://meta.discourse.org/t/command-line-disable-two-factor-authentication/121480/1 "2019-06-27T09:54:07Z")

</div>

Hello everyone,  
I have mistake that i delete Google Authentication Discourse on Mobile so Now i can’t login to Discourse.  
My question is … Can we disable Two Factor Authentication by command line SSH ?  
Thank you!

---

<div class="post-metadata">

### Author: ![Stephen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/stephen/32/95011_2.png) [@Stephen](https://meta.discourse.org/u/Stephen)
#### Post date: [June 27, 2019, 1:40pm UTC](https://meta.discourse.org/t/command-line-disable-two-factor-authentication/121480/2 "2019-06-27T13:40:49Z")

</div>

What happened to your backup codes?

---

<div class="post-metadata">

### Author: ![thaidb](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/thaidb/32/68488_2.png) [@thaidb](https://meta.discourse.org/u/thaidb)
#### Post date: [June 27, 2019, 1:54pm UTC](https://meta.discourse.org/t/command-line-disable-two-factor-authentication/121480/3 "2019-06-27T13:54:01Z")

</div>

I delete my Google authentication

 ![Screenshot_20190627-205440_Authenticator](https://global.discourse-cdn.com/meta/original/3X/5/7/579be01f806cc06de95abd16d3065583bc4cbee1.jpeg)

And i don’t save backup code

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [June 27, 2019, 4:38pm UTC](https://meta.discourse.org/t/command-line-disable-two-factor-authentication/121480/4 "2019-06-27T16:38:38Z")

</div>

> [@thaidb](#):
>
> Can we disable Two Factor Authentication by command line SSH ?

Yes, you can do this by updating the `enforce_second_factor` site setting to “no”. Enter the rails console and run:

```plaintext
 SiteSetting.enforce_second_factor = "no"

```

The available options for that setting are “no”, “staff”, and “all”.

---

<div class="post-metadata">

### Author: ![thaidb](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/thaidb/32/68488_2.png) [@thaidb](https://meta.discourse.org/u/thaidb)
#### Post date: [June 28, 2019, 2:40am UTC](https://meta.discourse.org/t/command-line-disable-two-factor-authentication/121480/5 "2019-06-28T02:40:11Z")

</div>

I want to disable two factor authentication all of account Discourse

 ![image](https://global.discourse-cdn.com/meta/original/3X/c/d/cde64dccb4058322a8635ab3aa967257b1dd30fd.png)

---

<div class="post-metadata">

### Author: ![thaidb](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/thaidb/32/68488_2.png) [@thaidb](https://meta.discourse.org/u/thaidb)
#### Post date: [June 28, 2019, 2:42am UTC](https://meta.discourse.org/t/command-line-disable-two-factor-authentication/121480/6 "2019-06-28T02:42:21Z")

</div>

![image](https://global.discourse-cdn.com/meta/original/3X/3/a/3a92834d1929fc003dcc55addb25af7ec39b1566.png)

---

<div class="post-metadata">

### Author: ![Dat\_Nguyen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dat_nguyen/32/160485_2.png) [@Dat\_Nguyen](https://meta.discourse.org/u/Dat_Nguyen)
#### Post date: [March 24, 2020, 7:01am UTC](https://meta.discourse.org/t/command-line-disable-two-factor-authentication/121480/7 "2020-03-24T07:01:02Z")

</div>

I am a newbie, and have the same problem. I deleted Factor Authentication on my phone without saving the backcode.  
Currently I cannot log in to the admin. Currently, I have no other staff to disable it from dasboard.  
Can anyone explain more about how to use this command ?:

> [@simon](#):
>
> Yes, you can do this by updating the `enforce_second_factor` site setting to “no”. Enter the rails console and run:
> 
> ```plaintext
> SiteSetting.enforce_second_factor = "no"
> 
> ```
> 
> The available options for that setting are “no”, “staff”, and “all”.

Thanks you

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [March 24, 2020, 7:01am UTC](https://meta.discourse.org/t/command-line-disable-two-factor-authentication/121480/8 "2020-03-24T07:01:40Z")

</div>

You need SSH terminal access to the server that Discourse is running on to proceed. Do you have that?

---

<div class="post-metadata">

### Author: ![Dat\_Nguyen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dat_nguyen/32/160485_2.png) [@Dat\_Nguyen](https://meta.discourse.org/u/Dat_Nguyen)
#### Post date: [March 24, 2020, 7:03am UTC](https://meta.discourse.org/t/command-line-disable-two-factor-authentication/121480/9 "2020-03-24T07:03:34Z")

</div>

> [@codinghorror](#):
>
> You need SSH terminal access to the server that Discourse is running on to proceed. Do you have that?

Yes, I have it, but I don’t know how with that command. Need to go to the Rails console? In fact, I don’t know how Rails works.

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [March 24, 2020, 11:50pm UTC](https://meta.discourse.org/t/command-line-disable-two-factor-authentication/121480/10 "2020-03-24T23:50:55Z")

</div>

> [@Dat\_Nguyen](#):
>
> Need to go to the Rails console? In fact, I don’t know how Rails works.

To access the rails console, ssh into your server. To do that, open a terminal on your computer and run:

`ssh root@<your_forum_ip_address>`

Replace `<your_forum_ip_address>` with the IP address of your Discourse site.

If that command is successful, you will see a prompt that looks something like this. Your IP address, or droplet name will be displayed instead of the word `testeleven`:

```plaintext
root@testeleven:~#

```

Type `cd /var/discourse` and hit your enter key.

Now type `./launcher enter app` and hit the enter key.

You should see a prompt that ends with something similar to this: `/var/www/discourse#`

At that prompt, type `rails c` and hit your enter key. You should now see a prompt that looks similar to this: `pry(main)> ` . This is the rails console.

To disable forced second factor authentication, type `SiteSetting.enforce_second_factor="no"` and hit your enter key.

To exit the SSH session, you will need to enter the word `exit` into the terminal three times. The first time is to exit the rails console, the second time is to exit the docker container, the third time is to exit the SSH session.

---

<div class="post-metadata">

### Author: ![Dat\_Nguyen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dat_nguyen/32/160485_2.png) [@Dat\_Nguyen](https://meta.discourse.org/u/Dat_Nguyen)
#### Post date: [March 25, 2020, 1:51am UTC](https://meta.discourse.org/t/command-line-disable-two-factor-authentication/121480/11 "2020-03-25T01:51:01Z")

</div>

> [@simon](#):
>
> Bạn sẽ thấy một dấu nhắc kết thúc bằng một cái gì đó tương tự như thế này: `/var/www/discourse#`
> 
> Tại dấu nhắc đó, nhập `rails c` và nhấn phím enter của bạn. Bây giờ bạn sẽ thấy một dấu nhắc trông giống như thế này : `pry(main)> ` . Đây là bảng điều khiển đường ray.
> 
> Để vô hiệu hóa xác thực yếu tố thứ hai bắt buộc, nhập `SiteSetting.enforce_second_factor="no"` và nhấn phím enter của bạn.

Thanks, the instructions are very clear and detailed. I did the following, but still required 2-factor authentication when logging in. Do not know where is wrong?

```
root@hoi-dap:/var/discourse# ./launcher enter app
root@hoi-dap-app:/var/www/discourse# rails c
[1] pry(main)> SiteSetting.enforce_second_factor='no'
=> "no"
[2] pry(main)> exit
root@hoi-dap-app:/var/www/discourse# exit
logout

```

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [March 25, 2020, 2:42am UTC](https://meta.discourse.org/t/command-line-disable-two-factor-authentication/121480/12 "2020-03-25T02:42:46Z")

</div>

Sorry, setting `SiteSetting.enforce_second_factor = "no"` will not solve your problem. You need to remove the second factor record for your user.

To do that, enter the rails console, then you need to find your user ID. To do that run:

```plaintext
id = User.find_by(username: '<your_username>').id

```

Replace `<your_username>` with your Discourse username. Make sure to keep the quotation marks. When you run the command, you should see a number returned. That number is your user ID. It has been assigned to the variable `id`.

Then you need to find the `UserSecondFactor` record that is associated with your user. This command uses the `id` variable that you set with the first command:

```plaintext
second_factor = UserSecondFactor.find_by(user_id: id)

```

When you run that command, you should see some output in the console that shows your second factor record.

Now destroy the record:

```plaintext
second_factor.destroy

```

You can exit the console after running that command. You should be able to login to your site after running it.

Let us know if you have any problems with this.

---

<div class="post-metadata">

### Author: ![Dat\_Nguyen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dat_nguyen/32/160485_2.png) [@Dat\_Nguyen](https://meta.discourse.org/u/Dat_Nguyen)
#### Post date: [March 25, 2020, 3:01am UTC](https://meta.discourse.org/t/command-line-disable-two-factor-authentication/121480/13 "2020-03-25T03:01:27Z")

</div>

> [@simon](#):
>
> To do that, enter the rails console, then you need to find your user ID. To do that run:
> 
> ```plaintext
> id = User.find_by(username: '<your_username>').id
> 
> ```
> 
> Replace `<your_username>` with your Discourse username. Make sure to keep the quotation marks. When you run the command, you should see a number returned. That number is your user ID. It has been assigned to the variable `id` .
> 
> Then you need to find the `UserSecondFactor` record that is associated with your user. This command uses the `id` variable that you set with the first command:
> 
> ```plaintext
> second_factor = UserSecondFactor.find_by(user_id: id)
> 
> ```
> 
> When you run that command, you should see some output in the console that shows your second factor record.
> 
> Now destroy the record:
> 
> ```plaintext
> second_factor.destroy
> 
> ```
> 
> You can exit the console after running that command. You should be able to login to your site after running it.

Thanks so much, it works great.  
However, I did not use the command `second_factor.destroy`. Instead, I took the data field to manually enter the Authenticator to recreate the two-factor authentication code.  
Yes, it worked perfectly. For added security, I will recreate the new validator.  
Thanks you.

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [April 24, 2020, 4:02am UTC](https://meta.discourse.org/t/command-line-disable-two-factor-authentication/121480/15 "2020-04-24T04:02:08Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
