項目托管的倉庫多了,使用的賬號多了,自然用到的key就不同了,比如gitlab,bitbucket, github, 公司的code倉庫等,所以管理好key很重要。
1,生成一個公司用的SSH-Key
$ ssh-keygen -t rsa -C "1email@company.com” -f ~/.ssh/id-rsa2,生成一個github用的SSH-Key
$ ssh-keygen -t rsa -C "2email@github.com” -f ~/.ssh/github-rsa此時,.ssh目錄下應該有4個文件:id-rsa和id-rsa.pub,github-rsa和github-rsa.pub,分別將他們的公鑰文件(id-rsa.pub,github-rsa.pub)內容配置到對應的code倉庫上
3,添加私鑰
$ ssh-add ~/.ssh/id_rsa $ ssh-add ~/.ssh/github_rsa如果執行ssh-add時提示”Could not open a connection to your authentication agent”,可以現執行命令:
$ ssh-agent bash# 然后再運行ssh-add命令。# 可以通過 ssh-add -l 來確私鑰列表$ ssh-add -l# 可以通過 ssh-add -D 來清空私鑰列表$ ssh-add -D4,修改配置文件
# 若.ssh目錄下無config文件,那么創建touch config# 添加以下內容# gitlabHost gitlab.com HostName gitlab.com PReferredAuthentications publickey IdentityFile ~/.ssh/id_rsa# githubHost github.com HostName github.com PreferredAuthentications publickey IdentityFile ~/.ssh/github_rsa5,測試
$ ssh -T git@github.com# 輸出Welcome to GitLab, your name!新聞熱點
疑難解答