我在 windows/Git bash/MingW64 上,尝试自动添加 ssh key 以与 git 一起使用。
我关注了这个 guide ,仅更改我的私钥文件的路径。
它似乎工作 - 当打开 git bash 我得到“成功
添加的身份:/c/users/...”。ssh-add -l
还显示我的 key 已正确添加,并且端口似乎已配置。
顺便说一句 - 在这一点上 $SSH_AGENT_PID
匹配 ps
中的进程和 $SSH_AUTH_PORT
似乎有效( /tmp/ssh-cEU4wbNe3vo4/agent.927
或类似的)
但是当我进入我的 git repo 并运行 git fetch
时我得到:
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
之后,ssh-add
不再有效,打印:Error connecting to agent: Bad file descriptor
这很奇怪,因为两者都是 $SSH_AUTH_PORT
和 $SSH_AGENT_PID
没变在这一点上,我已经尝试过 export
只是为了确定。启动一个新的 SSH-AGENT 并添加我的 key 在同一个终端 session 中工作,但尝试
git fetch
再次将具有相同的效果。git 在做什么会干扰 SSH 代理?
最佳答案
经过长时间的搜索,我终于找到了。 Windows 更新破坏了我的设置😒,特别是 Openssh。自上次 Windows 更新以来,我每次都必须输入我的密码,鉴于您的问题是最近出现的,我怀疑您也是如此。
我想Win32-OpenSSH#1693相关的。
在我的 ~/.gitconfig
在 [core]
有一条线(我不记得我之前遇到了什么问题)
sshCommand = C:/Windows/System32/OpenSSH/ssh.exe
删除它会出现此错误error: cannot spawn C:/Windows/System32/OpenSSH/ssh3.exe: No such file or directory
error: cannot spawn C:/Windows/System32/OpenSSH/ssh3.exe: No such file or directory
fatal: unable to fork
但是,将其替换为 sshCommand = "C:/Program\\ Files/Git/usr/bin/ssh.exe"
使一切都按我的预期工作。我想
Error connecting to agent: Bad file descriptor
意味着某些东西在引擎盖下崩溃了,考虑到它是最近发生的,很可能是由于 Openssl 更新。附言您可以通过检查
C:\Windows\System32\OpenSSH
中文件的“修改日期”来检查您的 OpenSSL 是否已更新。 .对我来说,这是最近的事情,与 ssh-agent 停止运行的那一刻一致。
关于git - Mingw-w64:ssh-add 工作直到 git fetch(连接到代理时出错:文件描述符错误),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67548300/