V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
wsgzao
V2EX  ›  程序员

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

  •  2
     
  •   wsgzao ·
    wsgzao · 2021-08-15 17:16:27 +08:00 · 4636 次点击
    这是一个创建于 956 天前的主题,其中的信息可能已经有所发展或是发生改变。

    今天提交代码,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 = [email protected]: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

    18 条回复    2021-08-17 09:05:29 +08:00
    icepie
        1
    icepie  
       2021-08-15 17:32:18 +08:00
    原来如此, 我以为是开了二步验证的问题
    lsvih
        2
    lsvih  
       2021-08-15 17:37:53 +08:00   ❤️ 2
    ```
    git remote set-url origin [email protected]:username/repo.git
    ```
    harwck
        3
    harwck  
       2021-08-15 17:39:59 +08:00
    Token 哪里麻烦了?就设置一下权限就好了。
    自从前几个月 GitHub 开始提醒的时候我就已经换到 Token 验证了。
    dingwen07
        4
    dingwen07  
       2021-08-15 18:09:30 +08:00
    一直都开着两步验证,这个变动应该没有影响
    xiangyuecn
        5
    xiangyuecn  
       2021-08-15 18:12:28 +08:00
    以前哪里填的密码,现在就在同样的位置填入 token 当做密码,大约 token == 密码 🐶
    dingwen07
        6
    dingwen07  
       2021-08-15 19:34:08 +08:00 via iPhone
    @xiangyuecn #5 密码可以用来生成 Token,但 Token 不能用于重置密码
    Mitt
        7
    Mitt  
       2021-08-15 19:47:17 +08:00
    本来其实直接用账户的密码的方式就不太合理的
    cweijan
        8
    cweijan  
       2021-08-15 19:48:04 +08:00
    现在把 token 当成密码就可以了, 比较麻烦的是需要清除掉以前保存的用户凭据
    fpure
        9
    fpure  
       2021-08-15 19:55:54 +08:00
    我想知道现在这个 token 是所有仓库共用一个 token 还是只能一个仓库一个 token ?
    Rheinmetal
        10
    Rheinmetal  
       2021-08-15 20:08:17 +08:00
    @fpure per repo 可以配 ssh key 吧
    yin1999
        11
    yin1999  
       2021-08-15 20:59:09 +08:00
    @fpure PAT(personal access token)是可以共用的
    beginor
        12
    beginor  
       2021-08-15 21:16:12 +08:00 via Android
    用 token 怎么试都不行,最后还是改用 ssh+key 了
    Trim21
        13
    Trim21  
       2021-08-16 07:55:31 +08:00 via Android
    最简单的办法是把远程地址换成
    https://username:[email protected]/username/repo.git
    Trim21
        14
    Trim21  
       2021-08-16 07:58:44 +08:00 via Android   ❤️ 1
    @Trim21 token 前面那个 username:也是可以省略掉的,直接 https://<token>@github.com/user/repo.git 也行
    istevenshen
        15
    istevenshen  
       2021-08-16 09:58:47 +08:00
    @Trim21 学习到了
    ysc3839
        16
    ysc3839  
       2021-08-16 10:41:55 +08:00
    个人觉得 token 并不麻烦,就只是把原来的密码换成 token,假如 token 麻烦的话原来用密码也一样麻烦。
    相反个人觉得 SSH 反而麻烦,比如配置代理不能简单地指定一个 http proxy 。
    Steaven
        17
    Steaven  
       2021-08-16 15:04:03 +08:00
    前天刚碰到这个问题,我还以为是因为我的库是私有库的原因。
    zliea
        18
    zliea  
       2021-08-17 09:05:29 +08:00
    一直在用 ssh 推,一直也不知道 0.0
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3163 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 13:03 · PVG 21:03 · LAX 06:03 · JFK 09:03
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.