GitHub认证失败

警告
本文最后更新于 2021-03-06,文中内容可能已过时。

最近新建了一个GitHub项目,想push代码上去,Terminal提示需要输入用户名和密码,就顺手输了用户名密码,结果提示

~ % git push
Username for 'https://github.com': username
Password for 'https://[email protected]':
remote: Invalid username or password.
fatal: Authentication failed for 'https://github.com/TinoGuo/exampleRepo/'

怎么回事,难道手贱输错了?于是再输了好几遍还是错误。去GitHub特地输了一遍账号密码,直接pass了。

难道用户名是邮箱?试了一遍还是上面的错误。于是Google搜索这个错误,最后终于解决了。

开启了GitHub的2FA验证,用户名密码不能直接用来登录了。

/books/2021/03/07/settings.png

/books/2021/03/07/developer_settings.png

/books/2021/03/07/personal_access_token.png

/books/2021/03/07/generate_token.png

~ % git push
Username for 'https://github.com': username
Password for 'https://[email protected]': 这里输入token
remote: Invalid username or password.
fatal: Authentication failed for 'https://github.com/TinoGuo/exampleRepo/'

当然GitHub也有官方Guide

https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token https://medium.com/@ginnyfahs/github-error-authentication-failed-from-command-line-3a545bfd0ca8