一步步使SSH连接您的github仓库
我之前都是用HTTPS的方式从我的本地git客户端连接github仓库的,每次都要输入用户名和密码,觉得很麻烦。
于是想到尝试SSH的方法连接,省去每次输入用户名和密码的麻烦。
首先查看自己用户目录下有没有这几个文件的存在:
![](https://user-images.githubusercontent.com/5669954/58926946-7086f580-877f-11e9-9619-c2620457fd4e.png)
我的目录下没有,
![](https://user-images.githubusercontent.com/5669954/58926947-7086f580-877f-11e9-9f06-b5b41cf28a6e.png)
那么就用下面的命令行生成:
ssh-keygen -t rsa -b 4096 -C “XXX@163.com”
注意引号里的XXX@163.com要替换成实际用来登录github网站的邮箱地址。
![](https://user-images.githubusercontent.com/5669954/58926948-711f8c00-877f-11e9-9efb-c2b1cfb178f8.png)
生成了两个文件id_rsa和id_rsa.pub:
![](https://user-images.githubusercontent.com/5669954/58926949-711f8c00-877f-11e9-966e-7456e18a754c.png)
启动本地的ssh-agent.
我的windows10使用的是Git for Windows v2.16.2这个客户端。
![](https://user-images.githubusercontent.com/5669954/58926950-711f8c00-877f-11e9-9480-423e808c65bb.png)
在安装目录的cmd文件夹下有ssh agent启动脚本。
![](https://user-images.githubusercontent.com/5669954/58926951-71b82280-877f-11e9-80ba-ffc28839d02f.png)
![](https://user-images.githubusercontent.com/5669954/58926952-71b82280-877f-11e9-8f45-508004e7d8b3.png)
![](https://user-images.githubusercontent.com/5669954/58926954-7250b900-877f-11e9-9546-276c073f938f.png)
一切就绪后,到github网站上创建一个新的ssh key:
![](https://user-images.githubusercontent.com/5669954/58926955-7250b900-877f-11e9-805b-9fc04676a85f.png)
将之前生成的本地文件id_rsa.pub的内容粘贴进去:
![](https://user-images.githubusercontent.com/5669954/58926956-72e94f80-877f-11e9-87d3-33fc0b01a2a8.png)
最后别忘了将github仓库的访问方式从https切换成ssh。
用git remote -v查看当前访问方式,确实为https。
![](https://user-images.githubusercontent.com/5669954/58926958-72e94f80-877f-11e9-93cb-fba9a9847c87.png)
![](https://user-images.githubusercontent.com/5669954/58926941-6f55c880-877f-11e9-8bbb-2b9aad8d4a0e.png)
在github网站上找到ssh访问的url:
![](https://user-images.githubusercontent.com/5669954/58926942-6f55c880-877f-11e9-815a-03e299e82a8c.png)
使用命令行切换成ssh方式访问:
git remote set-url origin git@github.com:i042416/KnowlegeRepository.git
![](https://user-images.githubusercontent.com/5669954/58926943-6fee5f00-877f-11e9-8b9a-397d5c6b8a7c.png)
现在做个测试,git push之后不会再有用户名和密码的提示了,ssh访问成功。
![](https://user-images.githubusercontent.com/5669954/58926945-6fee5f00-877f-11e9-9ffa-c32918e23686.png)
[外链图片转存失败(img-6E3vLpUy-1566608856970)(https://user-images.githubusercontent.com/5669954/58926678-965fca80-877e-11e9-8273-fd6e6e73a283.png)]要获取更多Jerry的原创文章,请关注公众号"汪子熙":
相关文章
- SSH SecureCRT
- 【解决】Ubuntu下使用SSH连接CentOS系统很慢
- 生成ssh-key for GIthub
- SSH 协议的 ssh StrictHostKeyChecking
- 一步步使SSH连接您的github仓库
- 【ubuntu】ubuntu下安装开启ssh服务
- xshell进行ssh链接报错“所选的用户密钥未在远程主机上注册”处理
- Win10:ssh报错:RSA host key for 192.168.3.10 has changed and you have requested strict checking.
- Mac 通过 ssh 远程登录服务器(密钥对(证书)方式)
- Github创建公钥SSH key的方法
- 防止暴力破解ssh的四种方法