GitLab: disable 2FA via console
May 7, 2024
Sometime the dedicated GitLab server crash the 2FA system. As a result, you can’t verify the 2FA step at sign-in page. A quick workaround is just temporary disable 2FA for a desired GitLab account. Here are steps to do.
Step 1 — Get GitLab Rail Console
SSH into your dedicated GitLab server. Then execute the following command:
gitlab-rails console
Verify return response, you should get something like this.
root@my-server:~# gitlab-rails console
Loading production environment (Rails 4.2.7.1)
irb(main):001:0>
Step 2 — Find target user
Run the following command in GitLab Rail Console.
User.where(username: "my-username")
Check return response before continue the next step.
Step 3 — Disable 2FA
User.where(username: "my-username").each(&:disable_two_factor!)
Done, the 2FA is now disabled on your account.
What’s next?
Test sign-in from web browser and re-enable 2FA if needed.
Happy Coding!