1 开始菜单Git Bash(Window环境)

2 鼠标右键打开Git Bash(Window环境)

3 如果没有安装ssh,那么使用下面的指令

1
sudo apt-get install ssh

4 检查SSH公钥 看看存不存在.ssh

1
cd ~/.ssh

如果提示:No such file or directory 说明你是第一次使用git。

5 生成SSH公钥

1
2
3
$ ssh-keygen -t rsa -C "邮件地址@youremail.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/your_user_directory/.ssh/id_rsa):<回车就好>

注意1: 此处的邮箱地址,你可以输入自己的邮箱地址;注意2: 此处的「-C」的是大写的「C」
然后系统会要你输入密码:

1
2
Enter passphrase (empty for no passphrase):<输入加密串>
Enter same passphrase again:<再次输入加密串>

在回车中会提示你输入一个密码,这个密码会在你提交项目时使用,如果为空的话提交项目时则不用输入。这个设置是防止别人往你的项目里提交内容。
最后看到这样的界面,就成功设置ssh key了:

6 获取SSH Key,现在你可以看到,在自己的目录下,有一个.ssh目录,说明成功了

1
cat ~/.ssh/id_rsa.pub

或者直接去目录下打开文件

7 测试是否生效

使用下面的命令测试

1
ssh -T git@github.com

如果是下面的反馈:

1
2
3
The authenticity of host 'github.com (207.97.227.239)' can't be established.
RSA key fingerprint is 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就好,然后会看到:

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