背景:因为某些神奇的原因,无法同时授权仓库权限给自己。
1.本地电脑只有权限访问web仓库地址,无权限访问backend仓库;
2.堡垒机服务器只有权限访问backend仓库,无权限访问web仓库地址。
web仓库地址 :codeup.aliyun.com:/xxx/xxx.web.git ,
backend仓库地址:codeup.aliyun.com:/xxx/xxx.backend.git ,
现在想在本地电脑或堡垒机服务器同时拉取两个仓库的代码。
解决办法
1 .将堡垒机服务器公钥私钥下载下来存放在本地.ssh目录中
(base) ☁ ~ tree .ssh
.ssh
├── config
├── id_rsa
├── id_rsa_dev # 堡垒机私钥
├── id_rsa_dev.pub # 堡垒机公钥
├── id_rsa.pub
└── known_hosts
2.修改.ssh/config的配置
Host aliyun-backendUser dev # 在服务器上的用户是devHostName codeup.aliyun.comPreferredAuthentications publickeyIdentityFile ~/.ssh/id_rsa_dev
3.拉取代码
● 1.使用aliyun-backend别名去替换codeup.aliyun.com拉取代码。
拉取的时候因为.ssh/config的地址映射,会自动解析仓库地址,使用对应的秘钥去拉取代码
git clone git@aliyun-backend:/xxx/xxx.backend.git
● 2.如果已经将代码仓库拷贝下来了,只需进入仓库目录修改远程目录即可。
cd ~/xxx.backend
git remote set-url origin git@aliyun-backend:/xxx/xxx.backend.git