How to set up 2FA on GitLab

Checked against GitLab's own help on 28 October 2026. Menus change, so follow the nearest label if yours differs.

Short answer

Open GitLab's security settings (Avatar, Edit profile, Access, Password and authentication), choose the authenticator app option, and scan the QR code GitLab shows with KeyNesta (or enter the setup key by hand). Type the six-digit code KeyNesta shows back into GitLab to finish, and save the recovery material GitLab gives you before you close the page.

Before you start

Have KeyNesta open and unlocked before GitLab shows the QR code, so the code is ready the moment it appears. KeyNesta needs no account to do this. It stores authenticator-app codes only: it does not do passkeys or hardware security keys, and where GitLab offers those you set them up in GitLab directly.

Steps

  1. Verify your email address first: GitLab asks for a verified address before two-factor authentication can be enabled.
  2. In the upper-right corner select your avatar, then Edit profile.
  3. In the left sidebar select Access, then Password and authentication.
  4. In the One-time password authenticator section select Register authenticator. GitLab displays a QR code and your OTP details.
  5. Add it to KeyNesta. Open the KeyNesta web app (or the app on your phone once it is released), unlock your vault, choose Scan QR and point the camera at the code on screen. If you cannot scan, use Import QR image, or choose Add entry to paste the setup key.
  6. Enter your current password, then the six-digit PIN KeyNesta generates, and select Register with two-factor app.
  7. GitLab then lists your recovery codes. Use Download codes (the file is gitlab-recovery-codes.txt) or print them, and keep them away from the phone.
GitLabWhat to know
Where to startAvatar, Edit profile, Access, Password and authentication
Setup key as textGitLab shows your OTP details beside the QR code and says you can enter the details provided to add the entry manually, so put that secret into KeyNesta with Add entry.
Recovery materialGitLab prompts you to download a set of recovery codes as soon as the authenticator is registered, and each code signs you in once.
SourceGitLab Docs: Two-factor authentication

Backup and recovery for GitLab

GitLab prompts you to download a set of recovery codes as soon as the authenticator is registered, and each code signs you in once. You can replace them from Edit profile, Access, Password and authentication, Recovery codes, Regenerate recovery codes, or over SSH with the command ssh git@gitlab.com 2fa_recovery_codes if the account has an SSH key; either way the previous set stops working. GitLab does not say how many codes a set holds, and no recovery codes are generated for WebAuthn devices.

Save whatever GitLab gives you somewhere that is not the phone holding your codes. Where to store your 2FA backup codes compares the options, and 2FA backup and sync covers backing up the KeyNesta vault itself.

Things to know about GitLab

Source

Menu paths on this page come from GitLab Docs: Two-factor authentication, read on 28 October 2026. The menu path, the OTP details beside the QR code, the recovery-code download and the personal-access-token rule come from GitLab's two-factor authentication page; the Recover your account route, the Regenerate recovery codes steps and the SSH command come from its two-factor authentication troubleshooting page. Neither states how many recovery codes a set holds, so this page does not either. KeyNesta is not affiliated with GitLab.

Frequently asked questions

Can I use KeyNesta as the authenticator app for GitLab?

Yes. GitLab asks for a standard time-based code, and KeyNesta reads the same QR code or setup key and generates that code on your device, offline. GitLab does not learn which app you chose. KeyNesta holds authenticator-app codes only; it has no passkey or hardware security key support. How to add the code is in How do I add a 2FA code to KeyNesta?

What happens to my GitLab 2FA if I lose my phone?

Select Recover your account on the two-factor verification screen and enter one of your recovery codes; if the account has an SSH key you can generate a fresh set first with ssh git@gitlab.com 2fa_recovery_codes. If your KeyNesta vault is synced or you made an encrypted backup, you can restore the codes on another device; the lost phone guide covers the order to do things in.

How do I add GitLab to KeyNesta if I cannot scan the QR code?

GitLab shows your OTP details beside the QR code and says you can enter the details provided to add the entry manually, so put that secret into KeyNesta with Add entry. In KeyNesta you can also upload a screenshot with Import QR image, paste an otpauth:// link, or add the entry by hand with the secret. Delete any screenshot of the QR afterwards: it works like a password.

Can I use the same GitLab code on two devices?

Codes come from a shared secret, so any app that holds the secret shows the same codes. The tidy way is KeyNesta's optional end-to-end encrypted sync, which carries the vault to a second device. The alternative is to add the secret to a second app while the QR code is still on screen; once GitLab stops showing it, you cannot get it back without re-enrolling.

Can I use passkeys with GitLab as well as KeyNesta?

GitLab supports passkeys, WebAuthn devices such as a YubiKey, and an email one-time password alongside an OTP authenticator, and says a passkey becomes an additional default option once 2FA is on. KeyNesta has no passkey or hardware security key support, so register those in GitLab and keep KeyNesta for the one-time password codes. GitLab also advises setting up an OTP even when you use a device, since recovery codes are not generated for WebAuthn devices.

Why does GitLab reject my password for git push after I turn on 2FA?

Because GitLab no longer accepts it there. Its docs say that with two-factor authentication enabled you cannot authenticate with a password for Git over HTTPS or for the API, and that you must use a personal access token instead. The code KeyNesta shows is for the sign-in screen.

Can I use KeyNesta for GitLab Self-Managed as well as GitLab.com?

Yes. GitLab documents the one-time password authenticator for GitLab.com, GitLab Self-Managed and GitLab Dedicated, and the menu path is the same on all three. Only the hostname changes, including in the SSH command for regenerating recovery codes.

How do I get new GitLab recovery codes once I have used them all?

Two ways, both in GitLab's docs. In the UI: your avatar, Edit profile, Access, Password and authentication, then Regenerate recovery codes in the Recovery codes section, confirmed with your password. Or over SSH with ssh git@gitlab.com 2fa_recovery_codes, which needs the private key for an SSH key already on the account. Either way the old codes stop working, so save the new set.

Try KeyNesta free. The web app needs no sign-up.

Open the web app All platforms