【问题标题】:SSH key not found when using system() to send git commands to command prompt in windows使用 system() 将 git 命令发送到 Windows 中的命令提示符时找不到 SSH 密钥
【发布时间】:2018-05-05 02:21:52
【问题描述】:

我正在尝试使用 R 中的 system() 函数(在 Windows 7 64 位上)使用公共 SSH 密钥执行 git 命令。当我尝试执行 git 命令时,出现以下错误:

ssh_askpass: exec(rpostback-askpass): No such file or directory
Host key verification failed.
fatal: Could not read from remote repository.

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

我可以在命令提示符下运行完全相同的命令并且它可以工作。我也可以在 git bash shell 上运行完全相同的命令并且它可以工作。我不确定为什么cmd 在使用system() 命令从R 运行时找不到密钥。有没有办法为system() 命令使用的命令提示符指定关键位置?

更新: 一个不起作用的示例调用:

system("git push --set-upstream git@gitlab.mygit.com:MyGroup/testGitlab.git master")

还有

system("git clone git@gitlab.mygit.com:MyGroup/gitLabTest.git")

这两个调用都得到上述相同的错误。

更新 2: 使用 list.files() 从 R 中似乎看不到 ssh 密钥

> list.files("C:/Users/Me/Documents/.ssh/", all.files = TRUE)
[1] "."  ".."

我已验证此目录中有多个 ssh 密钥,这些密钥在 git bash shell 中使用 ls -a 可见。

【问题讨论】:

  • 您对system() 的调用到底是什么样的?
  • 您的私钥密码是否受保护?
  • 不,密钥没有密码。同样,完全相同的命令在命令提示符下运行,无需任何额外输入。
  • 只是仔细检查:您的 shell 启动选项(.bashrc 等)不要使用 ssh-add 之类的东西来将密钥信息添加到钥匙串? env | grep SSH 能带你到任何地方吗?
  • @BenBolker 我不确定我是否理解您的问题?如果我打开 git bash (这是我生成密钥的地方),我可以查看密钥文件并且一切都按预期工作。在 Windows 命令提示符下,我可以毫无问题地从 gitLab 推送和拉取,但是当我在 .ssh 目录中 ls -a 时,我只得到 ...,没有可见的密钥文件。最后,当我尝试通过 R 会话中的system() 运行相同的命令时,我得到了上述 ssh 错误。感谢您的观看!

标签: r windows git ssh


【解决方案1】:

事实证明,在我的 Windows 系统(7、64 位)上,使用 git bash shell 创建 SSH 密钥时,它们被保存到“C:\Users\MyAcount\.ssh”。但是,system()R 中调用的cmd.exe 正在“C:\Users\MyAccount\Documents\.ssh”中查找。

由于某种原因,当使用直接从操作系统调用的cmd 提示符时,它会在与 bash shell 相同的 .ssh 目录中查找。去搞清楚。 Windows,我想我永远不会理解你。希望这可以帮助那里的人。

【讨论】:

    猜你喜欢
    • 2015-05-18
    • 2019-06-25
    • 2013-02-03
    • 1970-01-01
    • 1970-01-01
    • 2013-09-30
    • 1970-01-01
    • 2012-10-03
    • 1970-01-01
    相关资源
    最近更新 更多