因为涉及到SSH Key 对应多个远端仓库, github/gitee/gitlab等,需要生成多个SSH Key。
具体实现如下:
1.进入~/.ssh目录, 生成SSH Key
cd ~/.ssh
ssh-keygen -t rsa -C "your_name@email_name.com"
然后我们会看到如下信息,输入key的名字,不输入的话默认名字是id_ras
一路回车键,会生成id_rsa和id_rsa.pub 2个key
重复这一步,新建一个名字,如id_ras_company,
得到id_rsa_company和id_rsa_company.pub 2个key
2、输入配置文件
进入~/.ssh目录, 创建一个config文件,然后配置参数
cd ~/.ssh
touch config
vim config
输入格式如下:
#github
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
#gitee
Host gitee.com
HostName gitee.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
#company
Host git_company_url.com
HostName git_company_url.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_company
3、验证
仓库中配置SSH key //不同仓库的配置方法类似,github/gitee/gitlab具体百度哈
输入,验证success即可
ssh -T git@github.com
ssh -T git@gitee.com
ssh -T git@git_company_url.com
效果如下: