【问题标题】:The argument "-i" passed to GIT_SSH_COMMAND is being ignored传递给 GIT_SSH_COMMAND 的参数“-i”被忽略
【发布时间】:2018-07-30 09:31:51
【问题描述】:

我想为 git 使用其他 IdentityFile。我想动态使用它,而不是通过配置。我正在这样做:

  $ GIT_SSH_COMMAND='ssh -i /home/my_user/.ssh/id_ed25519' git pull origin master
  repository access denied.
  fatal: Could not read from remote repository.

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

发布密钥“id_ed25519.pub”在我的 bitbucket 中。

这也失败了:

  $ git pull origin master
  repository access denied.
  fatal: Could not read from remote repository.

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

还有:

$ git remote -v
origin  git@bitbucket.org:company123/repo456.git (fetch)
origin  git@bitbucket.org:company123/repo456.git (push)

添加 "-v"'ssh -i /home/my_user/.ssh/id_ed25519' 表明我的 RSA 密钥是正在使用,而不是 ED。为什么?

【问题讨论】:

    标签: git ssh public-key-encryption


    【解决方案1】:

    检查您的命令(是直接调用 git 还是通过别名调用)和配置:
    正如我在“Using GIT_SSH_COMMAND”中提到的, git config -l 可能会显示其他会覆盖环境变量的配置。

    检查git config core.sshCommand的返回。

    最后,GIT_SSH_COMMAND 表示 Git 2.10+,所以如果你的 Git 版本太旧,你需要先更新它。

    【讨论】:

    • “git too old”是我的问题。
    【解决方案2】:

    我在最近的 Ubuntu 版本中遇到了同样的问题:

    使用 -vvv 显示如下:

    debug2: key: /home/ubuntu/.ssh/id_rsa (0x5628e48246d0), agent
    debug2: key: /home/ubuntu/code/id_rsa (0x5628e4820af0), explicit
    

    添加-o IdentitiesOnly=yes 解决了它。

    完整的git 命令:

    GIT_SSH_COMMAND='ssh -o IdentitiesOnly=yes -i /home/ubuntu/code/id_rsa -F /dev/null' git pull
    

    【讨论】:

      【解决方案3】:

      如果有人在将GIT_SSH_COMMAND 设置在一行上,然后在另一行 实际运行git 命令时遇到此问题,请尝试以下方法之一:

      1. 在同一行设置GIT_SSH_COMMAND
      $ GIT_SSH_COMMAND="ssh -i ${key_location}" git clone [...]
      

      或者....

      1. 导出GIT_SSH_COMMAND
      $ export GIT_SSH_COMMAND="ssh -i ${key_location}"
      $ git clone [...]
      

      我在找到要使用的密钥后立即设置GIT_SSH_COMMAND,然后在几行之后运行git。我错误地删除了export,它破坏了git 命令。


      由于这是搜索“GIT_SSH_COMMAND”时最热门的 google 链接之一,并且该问题比答案更受欢迎,可能是某些访问者遇到与 OP 相同的问题,但原因与其他答案不同推荐。希望这对某人有所帮助。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-09-25
        • 2015-06-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-08-23
        • 2019-07-07
        相关资源
        最近更新 更多