Sometimes a self-hosted GitLab server has trouble with its 2FA system. When that happens, you can’t get past the 2FA step on the sign-in page, and you’re locked out. The quick fix I use is to temporarily turn off 2FA for the account that’s stuck. Here’s how I do it.
Step 1 — Open the GitLab Rails console
SSH into your GitLab server, then run:
gitlab-rails console
Give it a moment. You should see something like this:
root@my-server:~# gitlab-rails console
Loading production environment (Rails 4.2.7.1)
irb(main):001:0>
Step 2 — Find the user
Look up the account you want to fix:
User.where(username: "my-username")
Take a quick look at the response to make sure you’ve got the right user before moving on.
Step 3 — Disable 2FA
Now turn 2FA off for that user:
User.where(username: "my-username").each(&:disable_two_factor!)
That’s it, 2FA is now disabled on the account.
What’s next?
Try signing in from your browser to confirm it works, and re-enable 2FA later if you need it.
Happy Coding!