检查本机是否有ssh key设置
$ cd ~/.ssh 或cd .ssh
如果没有则提示: No such file or directory
有的话我们可以ls查看ssh文件
在ssh下存在3个文件,其中id_rsa和id_rsa.pub是我们需要的**了。
id_rsa是私钥,id_rsa.pub是公钥。
创建**,生成ssh key
如果没有ssh,通过ssh-****** -t rsa -C “输入你的邮箱” 创建**。
如果你有了还要创建密码,git会提示你是否需要覆盖(y/n)
当生成ssh key时
Enter file in which to save the key (/c/Users/diyvc/.ssh/id_rsa): #不填直接回车
Enter passphrase (empty for no passphrase): #输入密码(可以为空)
Enter same passphrase again: #再次确认密码(可以为空)
生成如上图所示标识生成成功了。其存放路径为:c:/Users/diyvc/.ssh/下。就在你C盘用户文件夹下。
查看ssh文件夹下,会发现id_rsa和id_rsa_pub。
将ssh key添加到github中。
登录GitHub系统;点击右上角账号头像的→Settings→SSH and GPG keys→New SSH key。
输入一个title和Key。我们用记事本或者UE等打开id_rsa.pub,将**复制进去就可以了。点击Add SSH key
如果在创建的时候添加了密码,输入密码
之后就可以看见在github上创建的ssh key了
测试ssh keys是否设置成功
$ ssh -T [email protected]
The authenticity of host ‘github.com (192.30.253.112)’ can’t be established.
RSA key fingerprint is is SHA256:nThbg6*******************ARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)? yes #确认你是否继续联系,输入yes
Warning: Permanently added ‘github.com,192.30.253.112’ (RSA) to the list of known hosts.
Enter passphrase for key ‘/c/Users/xxxx_000/.ssh/id_rsa’: #生成ssh kye是密码为空则无此项,若设置有密码则有此项且,输入生成ssh key时设置的密码即可。