Remote: Support for password authentication was removed on August 13, 2021.

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/jifanxi/helloworld002.git/'
 

这条信息表明,您在使用 Git 进行远程操作时,遇到了由于 GitHub 在 2021 年 8 月 13 日取消了密码认证支持而引发的问题。为了继续使用 Git 进行远程操作,您需要采用其他认证方法,例如使用个人访问令牌(Personal Access Token, PAT)或 SSH 密钥。

以下是如何使用个人访问令牌替代密码进行认证的步骤:

生成个人访问令牌

  1. 登录 GitHub
    打开 GitHub 网站并登录到您的账户。

  2. 进入设置
    点击右上角的头像,选择“Settings”。

  3. 进入开发者设置
    在左侧菜单中,选择“Developer settings”。

  4. 生成新令牌
    在左侧菜单中,选择“Personal access tokens”,然后点击“Generate new token”。

  5. 设置令牌权限
    给令牌命名,并选择所需的权限。对于基本的 Git 操作,选择 repo 范围(包括所有子权限)通常是足够的。

  6. 生成令牌
    点击“Generate token”按钮。生成后,记得将令牌复制并保存到安全的地方,因为您之后将无法再次查看它。

使用个人访问令牌进行 Git 认证

  1. 更新远程 URL
    将远程仓库的 URL 更新为使用令牌认证的格式。假设您的远程仓库 URL 是 https://github.com/username/repo.git,您可以这样更新:

    git remote set-url origin https://<your_token>@github.com/username/repo.git
    

    将 <your_token> 替换为您生成的个人访问令牌。

  2. 使用令牌进行操作
    现在,您可以像以前一样进行 git pushgit pull 等操作,Git 会使用您的个人访问令牌进行认证。

示例

假设您的 GitHub 用户名是 username,远程仓库 URL 是 https://github.com/username/repo.git,生成的个人访问令牌是 ghp_YourGeneratedToken12345,那么您可以在终端中执行以下命令:

git remote set-url origin https://ghp_YourGeneratedToken12345@github.com/username/repo.git

之后,您可以正常使用 Git 进行操作。

使用 SSH 密钥(可选)

如果您更喜欢使用 SSH 密钥进行认证,以下是简要步骤:

  1. 生成 SSH 密钥

    ssh-keygen -t ed25519 -C "your_email@example.com"
    

    按提示生成密钥对。

  2. 添加公钥到 GitHub
    将生成的公钥内容(通常在 ~/.ssh/id_ed25519.pub 文件中)复制并添加到 GitHub 中的“SSH and GPG keys”设置页面。

  3. 更新远程 URL
    将远程仓库 URL 更新为 SSH 格式:

    git remote set-url origin git@github.com:username/repo.git
    

通过这些步骤,您可以避免密码认证被移除带来的问题,继续顺利地使用 Git 进行代码管理。

  • 4
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值