為了安全性,個人的github和公司的gitlab需要配置不同的SSH-Key。具體如下:
- 切換到系統的SSH目錄
cd ~/.ssh
- 為個人的github生成SSH-Key(若還沒有)
ssh-keygen -t rsa -C "your_mail@example.com" -f github_rsa
然后,前往github添加SSH公鑰。
-
為公司的gitlab生成SSH-Key(若還沒有)
ssh-keygen -t rsa -C "your_mail@company.com" -f company_rsa
然后,前往gitlab添加SSH公鑰。
4. 添加配置文件(若還沒有)
``` shell
touch config
- 為配置文件
config
添加如下內容
# github.com
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/github_rsa
# gitlab.company.com
Host gitlab.company.com
HostName gitlab.company.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/company_rsa
- 測試
ssh -T git@github.com
輸出
Hi YK-Unit! You've successfully authenticated, but GitHub does not provide shell access.
以上表示成功連接到了個人的github。
然后可以用同樣方式測試公司的gitlab。