您的位置:首页 > 编程语言

一台电脑同时配置github私人账户和公司账户

2017-12-29 17:23 330 查看
参考:
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(2453929471@qq.com)
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_self
User 2453929471

# company(mgao@company.com)
Host github.company.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_company
User mgao

5. 测试

➜  .ssh ssh -T git@github.company.com
Hi mgao! You've successfully authenticated, but GitHub does not provide shell access.
➜  .ssh ssh -T git@github.com
             
Hi 2453929471! You've successfully authenticated, but GitHub does not provide shell access.

注意,我当时这里犯了一个错误,就是我用的 mgao@github.company.com去登录的,然后报publickey的错误。

官方文档写的很清楚


Always use the "git" user

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 git@github.com
Hi username! You've successfully authenticated...
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: