参考:
https://www.cnblogs.com/xjnotxj/p/5845574.html
http://blog.csdn.net/birdben/article/details/51824788
https://help.github.com/articles/error-permission-denied-publickey/
######################################
1. 两个账户分别生成ssh key
cd ~/.ssh
ssh-keygen -t rsa -C "2453929471@qq.com"
这个文件我叫它: id_rsa_self, 同时会生成一个id_rsa_self.pub
ssh-keygen -t rsa -C "mgao@company.com"
这个文件我叫它: id_rsa_company, 同时会生成一个id_rsa_company.pub
2. 添加私钥
ssh-agent -s
ssh-add ~/.ssh/id_rsa_self
ssh-add ~/.ssh/id_rsa_company
3. 分别登录私人和公司的github,配置ssh-key
将 id_rsa_xxx.pub的内容贴进去
4. 配置 config
cd ~/.ssh
touch config
# self([email protected])
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_self
User 2453929471
# company([email protected])
Host github.company.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_company
User mgao
5. 测试
➜ .ssh ssh -T [email protected]
Hi mgao! You've successfully authenticated, but GitHub does not provide shell access.
➜ .ssh ssh -T [email protected]
Hi 2453929471! You've successfully authenticated, but GitHub does not provide shell access.
注意,我当时这里犯了一个错误,就是我用的 [email protected]去登录的,然后报publickey的错误。
官方文档写的很清楚
All connections, including those for remote URLs, must be made as the "git" user. If you try to connect with your GitHub username, it will fail:
ssh -T GITHUB-USERNAME@github.com Permission denied (publickey).
If your connection failed and you're using a remote URL with your GitHub username, you can change the remote URL to use the "git" user.
You should verify your connection by typing:
ssh -T [email protected] Hi username! You've successfully authenticated...