Before you start
You need your GitHub password, a phone with an authenticator app on it, and somewhere safe to keep a small text file of recovery codes. Any standard authenticator app works, including Google Authenticator, Microsoft Authenticator and U2 Secured Authenticator, because GitHub uses the open TOTP standard.
If GitHub emailed you to say 2FA is now required on your account, you have 45 days from that notice, then a 7-day grace period. After that, GitHub blocks access to the website until 2FA is on. GitHub selects accounts that contribute code, for example by publishing releases, packages or actions, or by owning an organisation.
How to set up GitHub 2FA with an authenticator app
Do this on a computer, so the QR code is on one screen and the phone is in your hand.
- On GitHub, click your profile picture in the top-right corner, then Settings.
- In the sidebar, under Access, click Password and authentication.
- In the Two-factor authentication section, click Enable two-factor authentication. GitHub may ask for your password again.
- On your phone, open your authenticator app and add an account. In U2 Secured Authenticator, tap + Add account, then Scan QR code.
- Point the phone at the QR code under “Scan the QR code”. The app adds a GitHub entry showing a six-digit code. In U2 Secured, check the name and tap Save.
- Back on GitHub, type the current code into the box under “Verify the code from the app”.
- Under “Save your recovery codes”, click Download and store the file somewhere that is not your phone (see the next section).
- Click I have saved my recovery codes. Two-factor authentication is now on.
Can’t scan the QR code? Click “setup key” under the QR code to see the secret as text. In U2 Secured, tap + Add account, then Enter manually, type GitHub as the issuer and paste the key. Leave the advanced settings as they are.
Save your GitHub recovery codes
GitHub gives you 16 recovery codes. Each one signs you in once, without your phone. They are the difference between losing your phone and losing your GitHub account, because GitHub Support will not turn 2FA off for you.
Keep the downloaded file, called github-recovery-codes.txt, in a password manager you can open from another device, or print it and keep the paper somewhere safe. Do not keep it only on the phone that runs your authenticator app, or the phone takes both with it.
You can see them again later: Settings, then Password and authentication, then View next to Recovery codes. If you think someone else has seen them, or you have used several, click Generate new recovery codes there. The old set stops working the moment you do.
The 28-day check-up
For 28 days after you turn on 2FA, GitHub watches for one successful sign-in with it. Sign out and back in once with a code from the app and the check-up is over. If you never do, GitHub asks you to use 2FA in an existing session on day 28, and gives you a shortcut to set it up again if your app is not working. It is there to catch setups that were never tested, so test yours on day one.
Add a backup method
Once the authenticator app is set up, GitHub lets you add more methods, and adding one is the best protection against being locked out.
- A passkey or a security key. Passkeys and security keys are phishing-resistant, because the browser checks that it is really github.com before the key answers. A passkey can also sign you in without your password.
- GitHub Mobile, which approves sign-ins with a tap.
- Text message (SMS), only in the countries GitHub supports. GitHub recommends an authenticator app over SMS, and some organisations block members who use SMS.
Move GitHub 2FA to a new phone
If your authenticator app has a backup or a transfer feature, use that and every account moves at once. Our guides for Google Authenticator, Microsoft Authenticator and Authy cover each app. To move only GitHub, or to switch apps, re-add it from GitHub’s side while you can still sign in:
- Go to Settings, then Password and authentication.
- Under Two-factor methods, click Edit next to Authenticator app. If you have several methods, open the … menu next to it first.
- Scan the new QR code with the app on your new phone, or click “setup key” and enter it manually.
- Type the code from the new phone under “Verify the code from the app” and click Save.
- Sign out and back in with the new phone to check, then delete the old GitHub entry from the old phone.
After you click Save, codes from the old phone stop working for GitHub, because the secret has changed. Do not wipe the old phone until the new one has signed you in.
GitHub 2FA code not working?
Almost every rejected code comes down to one of these. Check them in order.
- The phone’s clock is off. Codes are made from the time, so set the date and time to automatic in your phone’s settings and try a fresh code.
- The code changed while you typed it. Wait for a new code and enter it straight away.
- You are reading the wrong entry. If you have more than one GitHub account, or an old entry from a previous setup, each has its own codes; use the one for the account you are signing in to.
- The secret was replaced. If you or anyone else reset 2FA on the account, old entries in your app no longer work. Use a recovery code, then set the app up again.
Lost your phone? How to get back into GitHub
With a recovery code: go to github.com/login, enter your username and password, then under More options click 2FA recovery code and enter one of the codes. Once you are in, set up your authenticator app again on the new phone and generate a new set of recovery codes.
With an app backup: restore your authenticator app on the new phone and the GitHub codes come back. Nothing changes on GitHub’s side.
With neither: GitHub has an account recovery process. On the sign-in page, click 2FA recovery code, then Begin account or email recovery. You verify an email address and prove you own the account with a device you have signed in on before, an SSH key or a personal access token. GitHub reviews it and replies within about three business days. If you have none of those, GitHub Support cannot restore access, which is why the recovery codes matter.
Using U2 Secured Authenticator for GitHub
U2 Secured Authenticator is our app for iPhone and Android. On the free plan it makes unlimited 2FA codes, locks with Face ID or your fingerprint, and works with no signal, so GitHub and every other TOTP site are covered at no cost. It can also lock the moment you leave it and hide codes until you tap one, which helps when you are sharing your screen.
Premium, at $14.99 a year, adds an end-to-end-encrypted backup: your codes are encrypted on your phone before upload, and only your password or a recovery key you keep can open them, so the backup is zero-knowledge: we cannot read your codes. They restore on a new iPhone or Android phone, and the web portal shows live codes, read-only, in any browser. That last part helps when you are at a computer without your phone. On the free plan there is no cloud backup, so your GitHub recovery codes are your safety net.