Skip to main content

Configuring two-factor authentication

You can choose among multiple options to add a second source of authentication to your account.

You can configure two-factor authentication using a mobile app or via text message. You can also add a security key.

We strongly recommend using a time-based one-time password (TOTP) application to configure 2FA. TOTP applications are more reliable than SMS, especially for locations outside the United States. TOTP apps support the secure backup of your authentication codes in the cloud and can be restored if you lose access to your device.

Warning:

  • If you're a member, billing manager, or outside collaborator to a private repository of an organization that requires two-factor authentication, you must leave the organization before you can disable 2FA on GitHub.com.
  • If you disable 2FA, you will automatically lose access to the organization and any private forks you have of the organization's private repositories. To regain access to the organization and your forks, re-enable two-factor authentication and contact an organization owner.

If you're a member of an 具有托管用户的企业, you cannot configure 2FA for your 托管用户 account. 2FA should be configured through your identity provider.

Configuring two-factor authentication using a TOTP mobile app

A time-based one-time password (TOTP) application automatically generates an authentication code that changes after a certain period of time. We recommend using cloud-based TOTP apps such as:

Tip: To configure authentication via TOTP on multiple devices, during setup, scan the QR code using each device at the same time. If 2FA is already enabled and you want to add another device, you must re-configure 2FA from your security settings.

  1. Download a TOTP app.

  2. 在任何页面的右上角,单击您的个人资料照片,然后单击 Settings(设置)

    用户栏中的 Settings 图标

  3. In the "Access" section of the sidebar, click Password and authentication.

  4. 在“Two-factor authentication(双重身份验证)”下,单击 Enable two-factor authentication(启用双重身份验证)启用双重身份验证选项

  5. Under "Two-factor authentication", select Set up using an app and click Continue.

  6. Under "Authentication verification", do one of the following:

    • Scan the QR code with your mobile device's app. After scanning, the app displays a six-digit code that you can enter on GitHub.
    • If you can't scan the QR code, click enter this text code to see a code that you can manually enter in your TOTP app instead. Click enter this code
  7. The TOTP mobile application saves your account on GitHub.com and generates a new authentication code every few seconds. On GitHub, type the code into the field under "Enter the six-digit code from the application". If your recovery codes are not automatically displayed, click Continue. TOTP enter code field

  8. 在“Save your recovery codes(保存恢复代码)”下,单击 Download(下载)将恢复代码下载到设备。 将它们保存到安全位置,因为如果您失去访问权限,恢复代码可以帮助您回到帐户。 要下载的恢复代码列表

  9. 保存双因素恢复代码后,单击 I have saved my recovery codes(我已保存恢复代码),以便为您的帐户启用双重身份验证。

  10. 在保存恢复代码并启用 2FA 后,建议注销并重新登录您的帐户。 如有问题,例如忘记密码或输错电子邮件地址, 您可以使用恢复码访问您的帐户并更正问题。

Configuring two-factor authentication using text messages

If you're unable to authenticate using a TOTP mobile app, you can authenticate using SMS messages. You can also provide a second number for a fallback device. If you lose access to both your primary device and your recovery codes, a backup SMS number can get you back in to your account.

Before using this method, be sure that you can receive text messages. Carrier rates may apply.

Warning: We strongly recommend using a TOTP application for two-factor authentication instead of SMS. GitHub doesn't support sending SMS messages to phones in every country. Before configuring authentication via text message, review the list of countries where GitHub supports authentication via SMS. For more information, see "Countries where SMS authentication is supported".

  1. 在任何页面的右上角,单击您的个人资料照片,然后单击 Settings(设置)

    用户栏中的 Settings 图标

  2. In the "Access" section of the sidebar, click Password and authentication.

  3. 在“Two-factor authentication(双重身份验证)”下,单击 Enable two-factor authentication(启用双重身份验证)启用双重身份验证选项

  4. Under "Two-factor authentication", select Set up using SMS and click Continue.

  5. Under "Authentication verification", select your country code and type your mobile phone number, including the area code. When your information is correct, click Send authentication code.

    2FA SMS screen

  6. You'll receive a text message with a security code. On GitHub, type the code into the field under "Enter the six-digit code sent to your phone" and click Continue.

    2FA SMS continue field

  7. 在“Save your recovery codes(保存恢复代码)”下,单击 Download(下载)将恢复代码下载到设备。 将它们保存到安全位置,因为如果您失去访问权限,恢复代码可以帮助您回到帐户。 要下载的恢复代码列表

  8. 保存双因素恢复代码后,单击 I have saved my recovery codes(我已保存恢复代码),以便为您的帐户启用双重身份验证。

  9. 在保存恢复代码并启用 2FA 后,建议注销并重新登录您的帐户。 如有问题,例如忘记密码或输错电子邮件地址, 您可以使用恢复码访问您的帐户并更正问题。

Configuring two-factor authentication using a security key

配置 2FA 后,使用基于时间的一次性密码 (TOTP) 移动应用,或通过短信,您可以添加安全密钥,如指纹读取器或 Windows Hello。 启用安全密钥身份验证的技术称为 WebAuthn。 WebAuthn 是 U2F 的继承者,适用于所有现代浏览器。 更多信息请参阅“WebAuthn”和“我可以使用”。

On most devices and browsers, you can use a physical security key over USB or NFC. Some browsers can use the fingerprint reader, facial recognition, or password/PIN on your device as a security key.

Authentication with a security key is secondary to authentication with a TOTP application or a text message. If you lose your security key, you'll still be able to use your phone's code to sign in.

  1. You must have already configured 2FA via a TOTP mobile app or via SMS.

  2. Ensure that you have a WebAuthn compatible security key inserted into your computer.

  3. 在任何页面的右上角,单击您的个人资料照片,然后单击 Settings(设置)

    用户栏中的 Settings 图标

  4. In the "Access" section of the sidebar, click Password and authentication.

  5. Next to "Security keys", click Add. Add security keys option

  6. Under "Security keys", click Register new security key. Registering a new security key

  7. Type a nickname for the security key, then click Add. Providing a nickname for a security key

  8. Activate your security key, following your security key's documentation. Prompt for a security key

  9. Confirm that you've downloaded and can access your recovery codes. If you haven't already, or if you'd like to generate another set of codes, download your codes and save them in a safe place. If you lose access to your account, you can use your recovery codes to get back into your account. For more information, see "Recovering your account if you lose your 2FA credentials." Download recovery codes button

  10. 在保存恢复代码并启用 2FA 后,建议注销并重新登录您的帐户。 如有问题,例如忘记密码或输错电子邮件地址, 您可以使用恢复码访问您的帐户并更正问题。

Configuring two-factor authentication using GitHub Mobile

You can use GitHub Mobile for 2FA when signing into your GitHub account in a web browser. 2FA with GitHub Mobile does not rely on TOTP, and instead uses public-key cryptography to secure your account.

Once you have configured a TOTP application, or SMS, you can also use GitHub Mobile to authenticate. If, in the future, you no longer have access to GitHub Mobile, you will still be able to use security keys or TOTP applications to sign in.

  1. You must have already configured 2FA via a TOTP mobile app or via SMS.
  2. Install GitHub Mobile.
  3. Sign in to your GitHub account from GitHub Mobile.

After signing in, you can now use your device for 2FA.

Further reading