一台电脑同时配置github私人账户和公司账户
參考:
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. 兩個(gè)賬戶分別生成ssh key
cd ~/.ssh
ssh-keygen -t rsa -C "2453929471@qq.com"這個(gè)文件我叫它: id_rsa_self, 同時(shí)會(huì)生成一個(gè)id_rsa_self.pub
ssh-keygen -t rsa -C "mgao@company.com"這個(gè)文件我叫它: id_rsa_company, 同時(shí)會(huì)生成一個(gè)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的內(nèi)容貼進(jìn)去
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. 測(cè)試
?? .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.
注意,我當(dāng)時(shí)這里犯了一個(gè)錯(cuò)誤,就是我用的 mgao@github.company.com去登錄的,然后報(bào)publickey的錯(cuò)誤。
官方文檔寫的很清楚
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...
總結(jié)
以上是生活随笔為你收集整理的一台电脑同时配置github私人账户和公司账户的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 软件开发学习路线
- 下一篇: ecshop $lang