简体   繁体   English

无法使用SSH代理转发运行git命令

[英]Can't run git commands using SSH agent forwarding

I want to run a git command on my VPS server, as in the following: 我想在我的VPS服务器上运行git命令,如下所示:

ssh -A user@mydomain.com 'git ls-remote git@bitbucket.org:myuser/repo.git'

but I get the error message: 但我收到错误消息:

Host key verification failed.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

I can run other commands using SSH agent forwarding. 我可以使用SSH代理转发来运行其他命令。 (On other servers, this commands works fine.) (在其他服务器上,此命令可以正常工作。)

The "Host key verification failed" message likely means that the SSH client on your VPS doesn't trust the git server. “主机密钥验证失败”消息可能意味着您的VPS上的SSH客户端不信任git服务器。

Try this instead: 尝试以下方法:

ssh -A user@mydomain.com 'ssh -T -o StrictHostKeyChecking=no git@bitbucket.org < /dev/null'
ssh -A user@mydomain.com 'git ls-remote git@bitbucket.org:myuser/repo.git'

The first command should cause the SSH key to be cached in your .ssh/known_hosts on the VPS. 第一条命令应将SSH密钥缓存在VPS上的.ssh/known_hosts From then on, the second command should work. 从那时起,第二个命令应该起作用。

You could probably also solve this by creating a .ssh/config on the VPS user account, containing something like this (untested): 您可能还可以通过在VPS用户帐户上创建一个.ssh/config来解决此问题,其中包含以下内容(未经测试):

Host bitbucket.org
    User git
    StrictHostKeyChecking no

Assuming the above configuraiton snippet works, it would save you one SSH connection. 假设上面的配置片段有效,它将为您节省一个SSH连接。

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

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