GitHub 不再支持密码验证解决方案: SSH 免密与 Token 登录配置

2021-08-15 17:16:27 +08:00
 wsgzao

今天提交代码,push 到 GitHub 上,突然出现这个问题。

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: unable to access 'https://github.com/wsgzao/wsgzao.github.io.git/': The requested URL returned error: 403

官方的解释:https://github.blog/changelog/2021-08-12-git-password-authentication-is-shutting-down/

As previously announced, starting on August 13, 2021, at 09:00 PST, we will no longer accept account passwords when authenticating Git operations on GitHub.com. Instead, token-based authentication (for example, personal access, OAuth, SSH Key, or GitHub App installation token) will be required for all authenticated Git operations.

Please refer to this blog post for instructions on what you need to do to continue using git operations securely.

Removal

  • August 13, 2021, at 09:00 PST

大致意思是,密码验证于 2021 年 8 月 13 日不再支持,也就是今天 intellij 不能再用密码方式去提交代码。请用使用 personal access token 替代。

这个去年年底就说了,https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/

In July 2020, we announced our intent to require the use of token-based authentication (for example, a personal access, OAuth, or GitHub App installation token) for all authenticated Git operations. Beginning August 13, 2021, we will no longer accept account passwords when authenticating Git operations on GitHub.com.

自己鼓捣了一遍 Token,烦人的很。还是觉得直接 ssh 的方式操作 git 就好(之前是 ssh 的源,也没有这个问题)。

以下两种解决方案推荐使用 SSH 免密登录

  1. GitHub 配置 SSH 免密登录
  2. GitHub token
# 登录 github 添加 SSH and GPG keys 公钥

# 修改 git config
vim wsgzao.github.io/.git/config

[core]
        repositoryformatversion = 0
        filemode = false
        bare = false
        logallrefupdates = true
        symlinks = false
        ignorecase = true
        hideDotFiles = dotGitOnly
[remote "origin"]
        url = https://github.com/wsgzao/wsgzao.github.io.git
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
        remote = origin
        merge = refs/heads/master

# 替换 url = 

[core]
        repositoryformatversion = 0
        filemode = false
        bare = false
        logallrefupdates = true
        symlinks = false
        ignorecase = true
        hideDotFiles = dotGitOnly
[remote "origin"]
        url = git@github.com:wsgzao/wsgzao.github.io.git
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
        remote = origin
        merge = refs/heads/master

Google 搜索到以下文章具体步骤非常详细,我就直接贴链接不再重复了

https://www.cnblogs.com/zhoulujun/p/15141608.html

4679 次点击
所在节点    程序员
18 条回复
icepie
2021-08-15 17:32:18 +08:00
原来如此, 我以为是开了二步验证的问题
lsvih
2021-08-15 17:37:53 +08:00
```
git remote set-url origin git@github.com:username/repo.git
```
harwck
2021-08-15 17:39:59 +08:00
Token 哪里麻烦了?就设置一下权限就好了。
自从前几个月 GitHub 开始提醒的时候我就已经换到 Token 验证了。
dingwen07
2021-08-15 18:09:30 +08:00
一直都开着两步验证,这个变动应该没有影响
xiangyuecn
2021-08-15 18:12:28 +08:00
以前哪里填的密码,现在就在同样的位置填入 token 当做密码,大约 token == 密码 🐶
dingwen07
2021-08-15 19:34:08 +08:00
@xiangyuecn #5 密码可以用来生成 Token,但 Token 不能用于重置密码
Mitt
2021-08-15 19:47:17 +08:00
本来其实直接用账户的密码的方式就不太合理的
cweijan
2021-08-15 19:48:04 +08:00
现在把 token 当成密码就可以了, 比较麻烦的是需要清除掉以前保存的用户凭据
fpure
2021-08-15 19:55:54 +08:00
我想知道现在这个 token 是所有仓库共用一个 token 还是只能一个仓库一个 token ?
Rheinmetal
2021-08-15 20:08:17 +08:00
@fpure per repo 可以配 ssh key 吧
yin1999
2021-08-15 20:59:09 +08:00
@fpure PAT(personal access token)是可以共用的
beginor
2021-08-15 21:16:12 +08:00
用 token 怎么试都不行,最后还是改用 ssh+key 了
Trim21
2021-08-16 07:55:31 +08:00
最简单的办法是把远程地址换成
https://username:token@github.com/username/repo.git
Trim21
2021-08-16 07:58:44 +08:00
@Trim21 token 前面那个 username:也是可以省略掉的,直接 https://<token>@github.com/user/repo.git 也行
istevenshen
2021-08-16 09:58:47 +08:00
@Trim21 学习到了
ysc3839
2021-08-16 10:41:55 +08:00
个人觉得 token 并不麻烦,就只是把原来的密码换成 token,假如 token 麻烦的话原来用密码也一样麻烦。
相反个人觉得 SSH 反而麻烦,比如配置代理不能简单地指定一个 http proxy 。
Steaven
2021-08-16 15:04:03 +08:00
前天刚碰到这个问题,我还以为是因为我的库是私有库的原因。
zliea
2021-08-17 09:05:29 +08:00
一直在用 ssh 推,一直也不知道 0.0

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/795911

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX