简体   繁体   English

git pull使用不同的SSH密钥

[英]git pull using different SSH key

I am trying to pull changes into a repo. 我正在尝试将更改纳入回购协议。 The repo's origin was originally located on a different git server, now the origin has moved to another server. 回购的来源最初位于其他git服务器上,现在该来源已移至另一台服务器。 On the new server we have a generic user called 'app', on other machines we have added the app user private key and a config file like so: 在新服务器上,我们有一个名为“ app”的通用用户,在其他计算机上,我们添加了该应用程序用户私钥和一个配置文件,如下所示:

# in /root/.ssh/config
Host gitlab-app
  HostName git.ist
  User git
  IdentityFile /root/.ssh/id_rsa_app
  IdentitiesOnly yes

and could use a command like this to clone the repo: 并可以使用如下命令克隆存储库:

git clone gitlab-app:software-development/my_repo.git

Which works. 哪个有效。 The problem is that on the particular server im talking about the repo had already been cloned from the previous location. 问题是在特定服务器上,我正在谈论该仓库的消息已经从先前的位置克隆了。 I've changed the remote url of the repo to the new location but when trying to pull over ssh I am asked for a password. 我已将存储库的远程URL更改为新位置,但是在尝试覆盖ssh时,要求输入密码。 I guess because there is no key from this server on the gitlab host. 我猜是因为在gitlab主机上没有来自此服务器的密钥。 Hence the generic 'app' user. 因此,通用的“ app”用户。

My question is, how do I configure my repo to use the app user key for ssh when I am running the pull command as root user? 我的问题是,当我以root用户身份运行pull命令时,如何配置我的仓库以将应用程序用户密钥用于ssh?

In some other threads I saw this: 在其他一些线程中,我看到了这一点:

git config core.sshCommand 'ssh -i ~/.ssh/id_rsa_app -F /dev/null'

But it had no effect for me. 但这对我没有影响。

Ok so it was a simple solution. 好的,所以这是一个简单的解决方案。 When I changed the remote-url of the repo on the server I just copied and pasted the standard url from the gitlab page. 当我在服务器上更改存储库的远程URL时,我只是从gitlab页面复制并粘贴了标准URL。 What I needed to change it to was: 我需要将其更改为:

from

git@git.ist:software-development/my_repo.git

to

gitlab-app:software-development/my_repo.git

So that the git config file is actually used. 以便实际使用git配置文件。 Just like in the clone link. 就像在克隆链接中一样。

So basically: 所以基本上:

git remote set-url origin gitlab-app:software-development/my_repo.git

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM