报错信息:
[root@vm1 ~]# git clone https://github.com/username/repo.git
Cloning into 'repo'...
Username for 'https://github.com': your_username
Password for 'https://username@github.com':
remote: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead.
remote: Please see https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/ for more information.
fatal: Authentication failed for 'https://github.com/Rockstics/docker.git/'
官网解释如下:
在 2020 年 7 月,我们宣布打算要求对所有经过身份验证的 Git 操作使用基于令牌的身份验证(例如,个人访问、OAuth 或 GitHub 应用安装令牌)。从 2021 年 8 月 13 日开始,在对 GitHub.com 进行 Git 操作进行身份验证时,我们将不再接受帐户密码
受影响的工作流
- 命令行 Git 访问
- 使用 Git 的桌面应用程序(GitHub Desktop 不受影响)
- 直接使用您的密码访问 GitHub.com 上的 Git 存储库的任何应用/服务
以下客户不受此更改的影响:
- 如果为帐户启用了双重身份验证,则已需要使用基于令牌或 SSH 的身份验证。
- 如果您使用 GitHub Enterprise Server,我们尚未宣布对本地产品/服务进行任何更改。
- 如果您维护的是GitHub 应用程序,则 GitHub 应用程序不支持密码身份验证。
解决方法
官网地址:https://docs.github.com/cn/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token
-
验证您的电子邮件地址,如果尚未验证。
-
在任何页面的右上角,单击您的个人资料照片,然后单击 Settings(设置)。
-
在左侧边栏中,单击 Developer settings。
-
在左侧边栏中,单击 Personal access tokens(个人访问令牌)。
-
单击 Generate new token(生成新令牌)。
-
给令牌一个描述性名称。
-
要使令牌过期,请选择 Expiration(到期)下拉菜单,然后单击默认值或使用日历选择器。
-
选择要授予此令牌的作用域或权限。 要使用令牌从命令行访问仓库,请选择 repo(仓库)。
-
单击 Generate token(生成令牌)。
-
在命令行上使用令牌
git clone https://github.com/username/repo.git
Username: your_username
Password: your_token