Git 配置SSH和使用
1.配置User Name和Email(如果第一次使用Git需要配置)
$ git config --global user.name "Your Name"
$ git config --global user.email "email@example.com"
配置自己的用户名和邮箱
注意:–global参数,表示你这台机器上所有的Git仓库都会使用这个配置。
2.生成密钥
$ ssh-keygen -t rsa -C "email@example.com"
连续回车,会得到两个文件:id_rsa和id_rsa.pub
3.在GitHub账户中添加你的公钥
把id_rsa.pub文件里的内容复制到这里
- 点击Settings
- 点击SSH and GPG keys
- New SSH key
- 复制
4.测试
输入
$ ssh -T git@github.com
会出现
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
如果出现下面信息,表示成功
Hi Your Name! You've successfully authenticated, but GitHub does not provide shell access.