mac上面配置多个不同仓库的SSH Key

同一台电脑会连接不同的远端仓库,github/gitlab等,就需要生成不同的SSH Key对应多个远端仓库。

这里只说明在mac上的操作。

1、进入~/.ssh目录下

cd ~/.ssh

2、生成SSH Key

ssh-keygen -t rsa -C "your_name@email_name.com"  // 后面的邮箱是你需要链接的远端仓库的账号邮箱

然后我们会看到如下信息,输入key的名字,不输入的话默认名字是id_ras

Generating public/private rsa key pair.
Enter file in which to save the key (/Users/beibei/.ssh/id_rsa): 

一路回车键,会生成id_rsa和id_rsa.pub 2个key

重复这一步,新建一个名字,如id_rsa_company,
得到id_rsa_company和id_rsa_company.pub 2个key

其中id_rsa是私钥 id_rsa.pub是公钥

3、执行下面的命令,将生成的key添加

ssh-add id_rsa

4、去github上面添加配置

id_rsa.pub里面的内容复制下来,在github上的settings里面找到add keys,将其粘贴到key即可,title随便填

5、输入配置文件

进入~/.ssh目录, 创建一个config文件,然后配置参数

cd ~/.ssh
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

6、验证

ssh -T git@github.com
ssh -T git@gitee.com
ssh -T git@git_company_url.com

输出

 

posted @ 2020-03-26 19:16  低调的人儿  阅读(550)  评论(0编辑  收藏  举报