GitHub中ssh key的使用,代码上传

github安装:https://git-scm.com/

点击download

打开Git Cmd

1、设置Git的user name和email:(如果是第一次的话)

$ git config --global user.name "john"
$ git config --global user.email "[email protected]"

2、生成密钥

$ ssh-keygen -t rsa -C "[email protected]"

连续3个回车,如果不需要密码的话。

最后得到了两个文件:id_rsa和id_rsa.pub(密钥在该文件中存放)

如果不是第一次,需要选择overwrite

3、添加密钥到ssh-agent

确保 ssh-agent 是可用的。ssh-agent是一种控制用来保存公钥身份验证所使用的私钥的程序,其实ssh-agent就是一个密钥管理器,运行ssh-agent以后,使用ssh-add将私钥交给ssh-agent保管,其他程序需要身份验证的时候可以将验证申请交给ssh-agent来完成整个认证过程。

$ eval "$(ssh-agent -s)"

Agent pid 6680

添加生成的SSH key到ssh-agent

扫描二维码关注公众号,回复: 1551104 查看本文章

$ ssh-add ~/.ssh/id_rsa

4、登陆github,如下图所示添加ssh key

密钥在id_rsa.pub文件中,用如下命令查看key并复制添加到github中

$ cat ~/.ssh/id_rsa.pub 


5、添加完成后进行测试,看到自己的名字了表示成功了

$ ssh -T [email protected]

The authenticity of host 'github.com (13.229.188.59)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,13.229.188.59' (RSA) to the list of known hosts.

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

然后就可以提交代码了


参考:https://segmentfault.com/a/1190000002645623

https://www.cnblogs.com/lixiaolun/p/5048954.html

猜你喜欢

转载自blog.csdn.net/leo062701/article/details/80552245
今日推荐