[Git] 一次搞定:Github 2FA(Two-Factor Authentication/两因素认证)

发布时间 2023-12-07 01:58:34作者: 千千寰宇

1 序言

1.1 由来

  • 一大早的,Github发来邮件要求我在45日内必须完成 两因素认证(2FA)

We're reaching out to let you know that, as announced last year, we have officially begun requiring users who contribute code on GitHub.com to have two-factor authentication (2FA) enabled.
正如去年宣布的那样,我们已经正式开始要求在GitHub.com上贡献代码的用户启用双因素身份验证(2FA)。

Your account meets this criteria, and you will need to enroll in 2FA within 45 days, by January 18th, 2024 at 00:00 (UTC). After this date, your access to GitHub.com will be limited until you enroll in 2FA. Enrolling is easy, and we support several options, starting with TOTP apps and text messages (SMS) and then adding on passkeys and the GitHub Mobile app.
您的帐户符合此标准,您需要在45天内,即2024年1月18日00:00 (UTC)之前注册2FA。在此日期之后,您对GitHub.com的访问将受到限制,直到您注册2FA。注册很容易,我们支持几个选项,从TOTP应用程序和短信(SMS)开始,然后添加密码和GitHub移动应用程序。

...

1.2 两因素认证(2FA):多因素用户认证体系的一种

  • 多因素用户认证(Multi-Factor Authentication),基本上各个大互联网平台,尤其是云平台厂商(如:阿里云的MFA、华为云、腾讯云/QQ安全中心等)都有启用了,Github算是搞得比较晚些了。

  • 对github有代码贡献的帐号要求进行2FA验证, 否则过期不能提交代码。

  • 但是github手机短信验证不支持中国号码(未亲测),这里介绍2种网友推荐的方式:

  • totp应用
  • 浏览器扩展

启用2FA之后,每次在不同设备上登录github都要输入验证码,【浏览器插件】可以生成验证码,但前提是需要先把【帐号】添加【扩展】中,【换设备登录】建议在【手机】上安装【totp应用】

2 配置过程

2.1 方式1:TOTP应用

方式1:亲测

推荐Microsoft Authenticator(以小米手机为例,应用商店可搜索到)

  • 其类似于【QQ安全中心】。
  • 每次打开都会生成一个动态验证码,用此验证码进行登录,在国内的应用商店中可以下载到或者从google play中下载。
  • Step1 进入2FA认证主页。长这样:

https://github.com/settings/two_factor_authentication/setup/intro

  • 或对应Github菜单路径:Github-Personal Center-Settings-Password and Authentication-(点击按钮: Enable Two-Factor Authentication)

https://github.com/settings/security

  • 从【Two-factor authentication】区域中选择 “Authenticator app”。

  • 选择【Edit】,就会打开一个 页面显示 QR 码(二维码), 请勿关闭此页面。

  • 打开手机【Microsoft Authenticator】应用,从右上角的【+】号添加帐户, (Google、Facebook 等) 选择其他帐户

  • 然后,手机【Microsoft Authenticator】应用扫一扫github页面上的这个QR码

  • 扫描完成之后,帐号就添加到Authenticator中了,下次打开切到github即可展示动态验证码。

  • 还需将手机【Microsoft Authenticator】应用的动态码输入到github页面下方的输入框中

  • 输完之后,将进入流程2的页面

该页面将提供【Recovery Code(恢复码)】,有很多个。

  • github将要求你必须下载下来保存好,便于哪天万一手机设备不可用或丢失时,可通过【恢复码】充当备用(相对于手机认证器)第2认证因子。

在第一次启用2FA后会给你一串码,下载下来保存这串码,关于这种恢复码的解释如下:
Recovery codes can be used to access your account in the event you lose access to your device and cannot receive two-factor authentication codes.
如果是第1次启用2FA,可以查看微软的文档:Add non-Microsoft accounts to the Microsoft Authenticator app - Microsoft Support

此时,就算真正完成了2因素认证了!

2.2 方式2:浏览器扩展

方式2:未亲测

  • 开源免费的Authenticator: 2FA Client,支持多种浏览器。

  • 切到github的设置- 安全页面,展示一个二维码,然后点击扩展上的扫描按钮,用鼠标选中github的二维码,即可添加github帐号。

Github URL : Authenticator-Extension/Authenticator: Authenticator generates 2-Step Verification codes in your browser. - Github
Edge扩展:Authenticator: 2FA Client - Microsoft Edge Addons

Edge Extension:Authenticator: 2FA Client - Microsoft Edge Addons

Google Extension:身份验证器 - Chrome 应用商店

X 参考文献

  • github