失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > 解决github提交代码Support for password authentication was removed 问题

解决github提交代码Support for password authentication was removed 问题

时间:2019-09-14 11:09:58

相关推荐

解决github提交代码Support for password authentication was removed 问题

一大早发现周末的代码commit之后没有push。按照之前的常规操作,采用用户名+密码的方式,通过https的方式push代码。结果出现如下错误:

remote: Support for password authentication was removed on August 13, . Please use a personal access token instead.remote: Please see https://github.blog/-12-15-token-authentication-requirements-for-git-operations/ for more information.fatal: unable to access '/zhoulujun/algorithm.git/': The requested URL returned error: 403

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

As previously announced, starting on August 13, , at 09:00 PST, we will no longer accept account passwords when authenticating Git operations on . 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.RemovalAugust 13, , at 09:00 PST

自8月13日以后,以用户名+密码的方式将不被支持。现在可以支持的方式有: OAuth、SSH Key或者GitHub App installation token) 。

个人对比了下,最便捷的方式就是采用ssh Key的方式了。

1.生成ssh密钥

ssh key的思路是,在本地,通过sshkeygan的方式,产生一组用于加密的RSA公私钥,之后,git在提交代码的过程中,通过本地的私钥加密,之后将加密数据传递到github服务器。

而对于github服务端,我们则需要将刚产生的公钥配置在github中,用于对数据的解密。这样就实现了ssh的方式提交代码。

第一步是产生ssh的rsakey,过程如下:

#打开git的shell窗口,先设置github账号的usernameAdministrator@DESKTOP-HR38DGU MINGW64 /c/Program Files (x86)$ git config --global user.name "haibo-duan"#设置emailAdministrator@DESKTOP-HR38DGU MINGW64 /c/Program Files (x86)$ git config --global user.email "dhaibo1986@"# 需要在D盘新建一个文件夹gitrep来存放生成的key文件Administrator@DESKTOP-HR38DGU MINGW64 /c/Program Files (x86)$ cd D:Administrator@DESKTOP-HR38DGU MINGW64 /d$ mkdir gitrepAdministrator@DESKTOP-HR38DGU MINGW64 /d$ cd gitrep/#执行init Administrator@DESKTOP-HR38DGU MINGW64 /d/gitrep$ git initInitialized empty Git repository in D:/gitrep/.git/#采用ssh-keygam -t -rsa产生密钥Administrator@DESKTOP-HR38DGU MINGW64 /d/gitrep (master)$ ssh-keygen -t rsaGenerating public/private rsa key pair.Enter file in which to save the key (/c/Users/Administrator/.ssh/id_rsa):Enter passphrase (empty for no passphrase):Enter same passphrase again:Your identification has been saved in /c/Users/Administrator/.ssh/id_rsa.Your public key has been saved in /c/Users/Administrator/.ssh/id_rsa.pub.The key fingerprint is:SHA256:********riiz4hYX5kGEpW6bLn8fkMwLvXbotBzflIM Administrator@DESKTOP-HR38DGUThe key's randomart image is:+---[RSA 2048]----+| +o || ... || o.. ||o .B.. ||.++.O S ||+o++ * o . ||oo+.O E + ||B+.*.* + . ||XB..+.o . |+----[SHA256]-----+

这样就生成了用于加密的公私钥文件。

产生的公私钥文件将放置在C:\Users\Administrator.ssh目录。如果在linux系统,这个位置就在用户所在的根目录中。

通过cat可以查看:

Administrator@DESKTOP-HR38DGU MINGW64 /d/gitrep (master)$ cat ~/.ssh/id_rsa.pubssh-rsa ********aC1yc2EAAAADAQABAAABAQDOsmo+mM3J6s9t07AyYWA5qwqPeMrkcKWTxVk7gyF1JY423txCOGhTNVGXLk59J4hyBJ67u9TAQpvatQpx0vk/8LUUSHlcDh4CU6U6S0gHtCi8dptG3q1SZwvvifDg6udj+fF4pR5pD0YN1DkQg22zNJzlYlAqu5sjW02+GeOxDKoyb+bIGYBxwIfcByb2fH9nahnyvfW8sCjoS0BzRRCh9HP3sKY6cLxajiNo6/e9bjVjocQkE9C7zOF7PNG8+AM3KMgf9qx2Cyvp7vimFDYjKuF3HSeNyhLEKQLyF5XDFBAI3KJ86G5yhpaljsSdI4y/cWVpzDU0+1ZUpRIOF3/z Administrator@DESKTOP-HR38DGU

这样产生的公钥,需要复制出来,在github上进行配置。

2.github配置

在github的 Setting部分:

将上述的公钥部分copy到此处保存。配置完成之后如下图:

3.切换本地project的协议

由于本地非常多的项目都是https方式进行提交,如果全部都通过ssh的方式重新clone之后再import,工作量非常大。可以采用命令行进行切换:

# 在本地的一个项目中打开git-shell,查看版本信息Administrator@DESKTOP-HR38DGU MINGW64 /d/workspace-mashibing/geektime-study (main)$ git remote -vorigin /haibo-duan/geektime-study.git (fetch)origin /haibo-duan/geektime-study.git (push)#切换Administrator@DESKTOP-HR38DGU MINGW64 /d/workspace-mashibing/geektime-study (main)$ git remote set-url origin git@:haibo-duan/geektime-study.git#再次查看Administrator@DESKTOP-HR38DGU MINGW64 /d/workspace-mashibing/geektime-study (main)$ git remote -vorigin git@:haibo-duan/geektime-study.git (fetch)origin git@:haibo-duan/geektime-study.git (push)

通过git remote set-url origin就能很好的切换。

需要注意的是,第一次提交会出现提示:

The authenticity of host '' can't be established. Are you sure you want to continue connecting (yes/no/[fingerprint])?..

确认无误则选择yes。

这样以后在idea中提交代码则不再需要输入密码了。

如果觉得《解决github提交代码Support for password authentication was removed 问题》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。