Jan*_*ker 5 git ssh continuous-integration github
我目前需要完成以下任务:我们的 CI 服务器需要使用与主项目存储库不同的 SSH(部署/签出)密钥从 GitHub 访问第二个存储库(GitHub 部署密钥仅是单个存储库。两个存储库 => 两个同一主机的 SSH 密钥。因此使用别名的想法)。然而,我们目前面临一些问题,我很确定我只是遗漏了一个细节。
假设我们的 git repo url 如下:
git@gitub.com:myorg/somerepo.git
Run Code Online (Sandbox Code Playgroud)
我们将其更改为:
git@gitub-second-account:myorg/somerepo.git
Run Code Online (Sandbox Code Playgroud)
然后我调整了 my.ssh/config
以使用引入的主机别名github-second-account
并将其映射回github.com
:
# Default GitHub user
Host github.com
HostName github.com
AddKeysToAgent yes
IdentityFile ~/.ssh/id_rsa
# Second account alias
Host gitub-second-account
HostName github.com
IdentityFile ~/.ssh/second_id_rsa
Run Code Online (Sandbox Code Playgroud)
我测试了我的设置并运行了以下命令:
ssh -T git@github-second-account
Run Code Online (Sandbox Code Playgroud)
GitHub 表示一切正常,身份验证成功。伟大的。(通过-vvv
使用正确的 SSH 密钥进行验证。)但现在我继续执行以下操作:
git clone git@gitub-second-account:myorg/somerepo.git
Run Code Online (Sandbox Code Playgroud)
并得到一个错误:
ssh: Could not resolve hostname gitub-second-account: nodename nor servname provided, or not known
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Run Code Online (Sandbox Code Playgroud)
是的,有一个关于访问权限的警告,我仔细检查了分配的 SSH 密钥是否确实具有权限(通过检查 github.com 并将我的更改.ssh/config
为使用该 SSH 密钥)并且 repo 顺利签出。我总觉得 git 不知何故无法解析主机名别名。
任何想法发生了什么?git clone --progress --verbose ...
遗憾的是,跑步没有提供更多信息。
小智 0
确保您的 SSH 代理中有正确的身份。虽然它可能在您的配置中指定,但我发现如果我运行:
ssh-add -D
Run Code Online (Sandbox Code Playgroud)
进而...
ssh-add ~/.ssh/theoneiwant
Run Code Online (Sandbox Code Playgroud)
这解决了这个问题。