配置github SSH公钥登录

摘要:
您已成功通过身份验证,但GitHub不提供外壳访问。3.修改git remoteurl。使用命令gitremote-v查看当前的remoteurl。以下是在生命游戏项目目录中执行的[root@kube-node1game-of-life]#gitremote voriginhttps://github.com/useyunwei/game-of-life.gitoriginhttps://github.com/useyunwei/game-如果上述结果是有效的。git,这意味着使用https协议访问项目。你可以登录到你的github。您可以看到上面ssh协议的相应url。与此类似:复制上述ssh链接,然后使用命令gitremoteseturl调整url。然后,您可以不用输入密码就轻松使用gitfetch、gitpull和gitpush

git的安装见https://www.cnblogs.com/liliyang/p/9829931.html

配置git使用ssh密钥

git支持https和git两种传输协议,github分享链接时会有两种协议可选:

配置github SSH公钥登录第1张

配置github SSH公钥登录第2张

 若git使用https协议,每次pull, push均提示要输入密码,使用git协议,然后使用ssh密钥对认证,即可实现免密

 
配置git 通过ssh协议免密需要三个步骤:
1、生成密钥对
2、配置远程仓库(这里使用github)上的公钥
3、把git的 remote url 修改为git协议(以上两个步骤初次设置过以后,以后使用都不需要再次设置,此步骤视以后项目的remote url而定,如果以后其他项目的协议为https则需要此步骤

 一、生成密钥对

[root@kube-node1 ~]# ssh-keygen  
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:fO7pVFqZ464nC8H6B3pTE8cwPx2mTM0G8KJt7Or2L8o root@kube-node1
The key's randomart image is:
+---[RSA 2048]----+
|          ...+   |
|          o.. *  |
|          .B.= . |
|       o +..Bo.  |
|        S =o*.   |
|       ..*o= .   |
|      ...o=..    |
|      .o+=+o.    |
|       +E*BBo    |
+----[SHA256]-----+
[root@kube-node1 ~]# ll .ssh/
total 8
-rw------- 1 root root 1679 Oct 23 11:32 id_rsa
-rw-r--r-- 1 root root  397 Oct 23 11:32 id_rsa.pub

[root@kube-node1 ~]# cat .ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDnjHeR/2hDtjMZKHND2kceUPSibuemNh0J/upA0DE/fmI8Ub52ZhJ1uY7STVntseR0HrJmed96KroD4uILE40ChKOwGZjptkFIWfZ+qCDYWpCqlUus2goiNlAj7WIYnlgzif/RSqn8wZNqqozi8JqU+g1gdWZCENU9C0ONeEwP83q1mATx26k8HGSN0Gg1V2zdKLUqEhEzQ/7FHEObDyZGT7NqAFfefgTLHr6lZslsHfqM7RdRBdf5zneSPSX264SgHIWFbgZKMyMVB+Um4jtdoQf2NpHAxIUfof1Ncn34KyPJ3PN2NEvkXhdKsSLohKiESe1hkYtDy+YagdqtwLf7 root@kube-node1

要将这里的公钥复制添加到github公钥配置中

二、添加公钥到自己的远程仓库(github)

配置github SSH公钥登录第3张

Title随便填写

 公钥复制到上述的Key中,点击Add SSH key

在本地主机上测试:

[root@kube-node1 ~]# ssh -T git@github.com
The authenticity of host 'github.com (192.30.253.113)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
RSA key fingerprint is MD5:16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,192.30.253.113' (RSA) to the list of known hosts.

Hi useyunwei! You've successfully authenticated, but GitHub does not provide shell access.

三、修改git的remote url

 使用命令 git remote -v (需在事先clone的项目目录中执行)查看你当前的 remote url

 下面是在game-of-life项目的目录中执行

[root@kube-node1 game-of-life]# git remote -v
origin https://github.com/useyunwei/game-of-life.git (fetch)
origin https://github.com/useyunwei/game-of-life.git (push)

如果是以上的结果那么说明此项目是使用https协议进行访问的(如果地址是git开头则表示是git协议)

可以登陆你的github,在上面可以看到你的ssh协议相应的url,类似:

 配置github SSH公钥登录第4张配置github SSH公钥登录第5张

复制上述的ssh链接,然后使用命令 git remote set-url 来调整url。

[root@kube-node1 game-of-life]# git remote set-url origin git@github.com:useyunwei/game-of-life.git
[root@kube-node1 game-of-life]# git remote -v
origin git@github.com:useyunwei/game-of-life.git (fetch)
origin git@github.com:useyunwei/game-of-life.git (push)

再次使用命令 git remote -v 查看一下,url是否已经变成了ssh地址。

然后就可以愉快的使用git fetch, git pull , git push,不用再输入密码

  

免责声明:文章转载自《配置github SSH公钥登录》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇Windows使用cmd命令行中查看、修改、删除与添加环境变量Python——pyHook监听鼠标键盘事件下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

git 生成patch 和打入patch

转载:https://blog.csdn.net/liuhaomatou/article/details/54410361 平时我们在使用git 管理项目的时候,会遇到这样一种情况,那就是客户使用git 生成patch 给到我们,那我们就需要把客户给到patch 打入到我们的project ,基于这样一个场景,我把git 如何生成patch 和如何打入pa...

anyproxy-windows平台安装和抓手机app上https请求

前言 做接口测试肯定离不开抓包,目前比较流行的抓包工具是fiddler和charles,相信并不陌生。这里介绍一个阿里公司研发的一个抓包神器,只需打开web页面,就能抓到手机app上的http和https请求了。这样就有个好处,当一个公司测试团队有多个人的时候,只需搭建一个AnyProxy服务,其它小伙伴浏览器上打开AnyProxy页面,手机上设置个代理就...

git拉代码,IntelliJ idea报错,cannot load module xxxxx

1 从git上下工程的时候,IntelliJ idea报错,cannot load module xxxx VCS-git-clone-ssh:xxxx ,报错cannot load module xxxx,然后项目目录不显示代码 查看左下角log:cannot load module xxx,xxx.iml does not exist,iml文件不存在...

IDEA分析JAVA内存溢出和内存泄漏

参考资料: 1、JProfiler分析dump文件   https://blog.csdn.net/axin1240101543/article/details/105142141 2、JProfiler使用教程 https://www.cnblogs.com/jpfss/p/11057440.html https://segmentfault.com/a...

Nginx https加密以及nginx日志配置与管理

Nginx https加密以及nginx日志配置与管理使用Nginx的优点Nginx作为WEB服务器,Nginx处理静态文件、索引文件、自动索引的效率非常高。Nginx作为代理服务器,Nginx可以实现无缓存的反向代理,提高网站的性能Nginx作为负载均衡服务器,内部可以支持PHP、也可以支持HTTP代理服务器对外进行服务,同时还支持简单的容错和利用算法进...

Json对象转Ts类

一 目标 推荐一款在线将Json对象转换为Ts类的工具:https://apihelper.jccore.cn/jsontool 可以帮助前端开发人员提高开发效率。 二 背景 Json是一种轻量级的数据交换格式。易于人阅读和编写。同时也易于机器解析和生成。所以Json成为了前后端交互使用的主要格式。 Typescript作为一种前端开发语言,应用也越来越广...