mac 添加多個git賬號
阿新 • • 發佈:2018-07-06
ide xxxxxx -s ssh-add 成功 hub use .com ati
mac生成多個賬號
啟動ssh-agent 服務方式
- 生成多個名稱的公密鑰
ssh-keygen -t rsa -C "[email protected]"
# Generating public/private rsa key pair...
# 三次回車即可生成 ssh key
# 第一次回車修改默認密鑰名稱 比如: github.com
- 啟動ssh-agent服務
$ eval "$(ssh-agent -s)"
Agent pid 2429
- 在ssh-agent服務中把剛新增加ssh-key添加進去
$ ssh-add ~/.ssh/github.com Identity added: /Users/andyniu/.ssh/gitee.com (/Users/andyniu/.ssh/gitee.com)
這種可能會有問題,當你關閉終端時候可能會失效
加配置文件config
- 創建config配置文件
$ touch ~/.ssh/config
編輯config文件
#該文件用於配置私鑰對應的服務器 #gitHub user(useremail@***.com) Host github.com HostName github.com User git #用戶 IdentityFile ~/.ssh/id_rsa_github.com ###################################### #Add gitLab user(chen@****.com) Host git.****.com HostName git.****.com User git IdentityFile ~/.ssh/id_rsa_***
- 驗證
$ ssh -T [email protected]
Hi username! You've successfully authenticated, but GitHub does not provide shell access.
# 上面是github的成功返回語句,下面是gitlab的成功返回語句。
$ ssh -T [email protected]
Welcome to GitLab, username!
mac 添加多個git賬號