标签(空格分隔): git github
1 测验SSH公钥是否添加到Github账户中
[ahcj@localhost ~]# ssh -T git@github.com
Warning: Permanently added the RSA host key for IP address '192.30.255.113' to the list of known hosts.
Permission denied (publickey).
上面的例子显示登录失败,这是因为我们还未在GitHub账户中添加SSH公钥。这时需要在本地创建SSH公钥,然后将生成的SSH公钥的文件内容添加到Github帐号上去。
2 生成SSH公钥
[ahcj@localhost ~]ssh-keygen -t rsa -C "your_email@youremail.com"
一路按 enter 键,最后会在.ssh目录生产两个文件:id_rsa和id_rsa.pub。
其中/.ssh/id_rsa是私钥文件,/.ssh/id_rsa.pub是公钥文件。
3 添加SSH公钥
# 将公钥输出到剪切板
[ahcj@localhost ~]cat ~/.ssh/id_rsa.pub | xclip -selection clipboard
# 或者使用 vim 打开 复制所有内容
[ahcj@localhost ~]vim ~/.ssh/id_rsa.pub
登录你的Github帐号后
- 点击右上方的Accounting settings图标
- 选择 SSH keys
- 点击 Add SSH key
- 在Title里填一个你自己喜欢的名称,然后将上面拷贝的~/.ssh/id_rsa.pub文件内容粘帖到Key中
- 点击“add key”按钮
4 测试SSH连接Github
[ahcj@localhost ~]$ ssh -T git@github.com
Warning: Permanently added the RSA host key for IP address '192.30.255.113' to the list of known hosts.
Hi xingchuan! You've successfully authenticated, but GitHub does not provide shell access.
5 设置git用户名与邮箱
[ahcj@localhost ~]git config --global user.name "Your Name Here"
[ahcj@localhost ~]git config --global user.email "your_email@example.com"