git管理密钥配置

这篇博文介绍了如何配置git密钥,并在github使用git密钥来进行远程连接鉴权。

git下载

下载地址

git配置

1
2
git config --global user.name "你的GitHub用户名"
git config --global user.email "你的GitHub注册邮箱"

生成密钥

1
2
3
4
5
ssh-keygen -t rsa -b 4096 -C "你的GitHub注册邮箱"

Enter file in which to save the key // 密钥保存位置,回车默认
Enter passphrase (empty for no passphrase): // 输入密码,直接回车
Enter same passphrase again: // 输入确认密码,直接回车

github密钥管理

github密钥管理直达链接
1)New SSH Key,复制本地 ~/.ssh(window下为 C:\User\用户.ssh)的 id_rsa.pub
2)Title为标题,任意填即可,将刚刚复制的id_rsa.pub内容粘贴进去
3)最后点击Add SSH key。

检验

在Git Bash中检测GitHub公钥设置是否成功,输入
ssh -T git@github.com


为不同网站应用各自的 SSH KEY

编辑ssh配置 vim ~/.ssh/config
追加以下内容

1
2
3
4
5
6
7
8
9
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_a

Host git.oschina.net
HostName git.oschina.net
User git
IdentityFile ~/.ssh/id_rsa_b