场景:
1、同一台电脑,需要通过git拉取相同代码库不同账号使用ssh
2、使用的同一个代码库(地址一样)
3、使用不同的代码库账号,分别使用不同的ssh密钥
(1)通过命令创建自己需要的密钥
ssh-keygen -t rsa -C "title01"
ssh-keygen -t rsa -C "title02"
注意:非首次创建的时候需要重新定义名称,要不然会覆盖
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/fuyue/.ssh/id_rsa):这里输入自己保存的地址
(2)在~/.ssh/目录下创建config文件
Host title01
HostName codeup.aliyun.com
IdentityFile ~/.ssh/title01_id_rsa
Host title02
HostName codeup.aliyun.com
IdentityFile ~/.ssh/title01_id_rsa
(3) 使用git命令拉取代码的写法
git clone git@codeup.aliyun.com:888888/study/****.git
改成:
git clone git@title01:888888/study/****.git
其中的title01对应着config中Host配置的密钥文件地址
ps:虽然是不同的代码库账号,但是实际上是可以配置相同的密钥的,也就是上面我们只需要创建一个密钥,在不同的账号下都进行配置也能解决上面的场景