在 Windows 中使用 system() 将 git 命令发送到命令提示符时找不到 SSH 密钥

roc*_*t44 2 windows git ssh r

我正在尝试使用 R 中的函数(在 Windows 7 64 位上)使用公共 SSH 密钥执行 git 命令system()。当我尝试执行 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.
Run Code Online (Sandbox Code Playgroud)

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

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

system("git push --set-upstream git@gitlab.mygit.com:MyGroup/testGitlab.git master")
Run Code Online (Sandbox Code Playgroud)

system("git clone git@gitlab.mygit.com:MyGroup/gitLabTest.git")
Run Code Online (Sandbox Code Playgroud)

这两个调用都会出现上述相同的错误。

更新 2:看起来 ssh 密钥在 R 中不可见,使用list.files()

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

我已经验证该目录中有多个 ssh 密钥,可以使用 git bash shell 看到这些密钥ls -a

roc*_*t44 5

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

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