How to Set Up 2FA on GitHub With an Authenticator App

Your GitHub account holds your code, your private repositories, and often the keys to your production servers. If someone takes it over, they can push malicious code and steal secrets. That is why two-factor authentication (2FA) is now required for anyone who contributes code on GitHub.
This guide shows you how to set up GitHub two-factor authentication with an authenticator app. It takes about five minutes, and it protects everything connected to your account.
If you are new to the idea, our beginner’s guide explains what two-factor authentication is.
Before You Start
You will need: your GitHub account, signed in; an authenticator app on your phone (or a browser tab with a code generator); and a safe place to store recovery codes.
If you do not have an authenticator app installed, you can generate codes in your browser with 2Fakey — try it free on 2Fakey — https://2facc.com/. It needs no install and works offline once the page has loaded.
Step 1: Open Your GitHub Security Settings
- Click your profile picture in the top-right corner and choose Settings.
- In the left sidebar, under Access, click Password and authentication.
- Find the Two-factor authentication section. You will see your current status and a button to enable it.
- Click Enable two-factor authentication. GitHub may ask you to confirm your password first.
Step 2: Choose an Authenticator App
GitHub offers a few second-factor options. Choose Authenticator app (listed as “TOTP app” in some versions of the page). SMS is also available, but the app is better — it works offline and codes never travel over the network. See TOTP vs SMS 2FA: Which One Is Safer?.
Step 3: Scan the QR Code
GitHub will show you a QR code and a text secret key (sometimes labelled “setup key”).
- Open your authenticator app and choose Add account (or the + button).
- Point your camera at the QR code on the screen.
- The app will add a GitHub entry and start showing six-digit codes that change every 30 seconds.
If you cannot scan the code, click the option to show the secret key as text. Copy it and paste it into your authenticator app — or paste it into 2Fakey at https://2facc.com/ to generate your codes in the browser.

Step 4: Enter the Code to Confirm
- GitHub asks for the six-digit code from your authenticator app.
- Type the code shown right now. If it is about to expire, wait for the next code and enter that one.
- Click Verify (or Continue).
If the code is accepted, GitHub confirms that two-factor authentication is enabled.
Step 5: Save Your Recovery Codes
This is the step people skip — and regret later. GitHub gives you recovery codes for signing in if you lose your phone.
- After verification, GitHub shows your recovery codes. There are usually 16 of them.
- Click Download to save them as a file, or Copy them into your password manager.
- Store them somewhere safe and separate from your phone — a password manager, an encrypted note, or a printed page in a drawer.
On the same settings page you can also add a security key as a second method, or SMS as a fallback. If you ever lose your phone without recovery codes, GitHub’s recovery process requires identity verification and can take days — see our guide to lost phone 2FA recovery.
Step 6: What Changes After Setup
Once 2FA is on: enter your username and password, then type the six-digit code from your authenticator app. On a trusted device, tick “remember this device” so you are not asked every time.
A few things that are specific to GitHub:
- Git over HTTPS will ask for a personal access token instead of your password. Create one under Settings → Developer settings → Personal access tokens. SSH keys keep working as before.
- Codes expire every 30 seconds. If one fails, wait for the next. Make sure your phone’s clock is set to automatic.
- Signing in from a new device always requires a code, even on devices you have trusted before.
- Organization requirements. Some organizations require 2FA for all members. If you join one, you will be prompted to enable it before you can contribute.

Why GitHub Requires 2FA
GitHub made 2FA mandatory for contributors because developer accounts are high-value targets: one compromised maintainer can inject malicious code into software used by thousands of people. Even personal projects may hold API keys and deployment credentials — 2FA is cheap insurance for all of it.
Troubleshooting: Common Problems
“The code isn’t working.” Wait for the next code and check your phone’s time is set to automatic — even a minute of drift breaks TOTP codes.
“I can’t find the 2FA setting.”
Make sure you are signed in to the right GitHub account. The path is: profile picture → Settings → Password and authentication → Two-factor authentication.
“Git is asking for a password and mine doesn’t work.” With 2FA on, Git over HTTPS no longer accepts your account password — use a personal access token instead, or switch to SSH.
“I lost my phone.” Use a recovery code to sign in, then set up 2FA again. Without recovery codes, GitHub’s account recovery process requires identity verification and takes time.
“I need to use GitHub on a new phone.” Set up your authenticator app on the new phone first, then sign in with a fresh code.
The Bottom Line
GitHub two-factor authentication takes five minutes and protects your code, your repositories, and every service connected to your account. Use an authenticator app, save your recovery codes, and create a personal access token for Git over HTTPS.
Frequently Asked Questions
Is GitHub two-factor authentication required?
Yes, for anyone who contributes code. GitHub requires 2FA for all users who push code. Even if you only read code, enabling it is strongly recommended.
Can I use 2Fakey for GitHub 2FA?
Yes. GitHub's setup shows a standard QR code and secret key that any TOTP authenticator can use — including 2Fakey in your browser at https://2facc.com/. Paste the secret key GitHub shows you.
What is a personal access token, and why do I need one?
With 2FA on, Git over HTTPS no longer accepts your account password. A personal access token is a token you create in GitHub’s Developer settings and use in place of your password when Git asks. SSH keys are not affected.
Set up 2FA on your GitHub account today — and generate your codes free with 2Fakey at https://2facc.com/.
