最近又是换电脑,又是换硬盘的,来来回回搞了好几次,遂记录一下,最简单的流程。
1.为什么要用ssh?
平时用的是https链接,所以push等操作都得输入用户名密码,很烦,但是认证了ssh链接之后,就可以在此台机器上随意操作项目了。
2.本地部署ssh
Windows:
cd ~/.ssh #进入ssh文件夹
# bash: cd: /c/Users/wayne/.ssh: No such file or directory
如果是新电脑,以前没连过ssh,会出现这个问题,我今天刚换硬盘就出现了这个问题,可以先忽略上一步,进行下一个代码,等三次回车创建成功之后,再执行上一步,进入ssh,就ok了~
ssh-keygen -t rsa -C "your_email@example.com" #创建ssh key ... #回车使用默认文件名 Enter file in which to save the key (/c/Users/you/.ssh/id_rsa): [Press enter] #回车使用空密码 Enter passphrase (empty for no passphrase): Enter same passphrase again: ... #出现如下表示创建成功 Your public key has been saved in /c/Users/you/.ssh/id_rsa.pub.
#查看公钥
cat id_rsa.pub
#复制命令行显示的公钥,全部复制
3.GitHub添加ssh
进入setting
4.测试ssh
ssh -T git@github.com ... Are you sure you want to continue connecting (yes/no)? #输入yes回车 Enter passphrase for key '/c/Users/Administrator/.ssh/id_rsa': #继续回车 Hi username! You've successfully authenticated, but GitHub does not provide shell access.
大功告成~