适用于Windows的Git:无法将主机添加到known_hosts,用户目录错误

rwqw0loc  于 2022-12-14  发布在  Windows
关注(0)|答案(1)|浏览(367)

Git for Windows在使用SSH验证时运行良好。但是,SSH服务器的签名发生了变化。我删除了~/.ssh/known_hosts文件,希望ssh能重新创建它。但是,当我尝试通过SSH推送到远程时,我得到了以下消息:
假设我的Windows用户名是“abc”。

$ git push
 Could not create directory '/home/abc/.ssh' (No such file or directory).
 Failed to add the host to the list of known hosts (/home/abc/.ssh/known_hosts).
 git@my_bitbucket.hu: Permission denied (publickey).
 fatal: Could not read from remote repository.

在Windows上我没有/home/abc目录。$HOME被设置为“/c/Users/abc”。我该如何解决这个问题?我尝试了On windows, could not create directory '/home//.ssh'中的几个解决方案,但都没有效果。
在Wondows CMD中,%HOME%和%USERPROFILE%被设置为“/c/Users/abc”。为什么ssh试图访问“/home/abc/.ssh”下的文件?

46scxncf

46scxncf1#

在CMD会话中尝试相同的操作(没有git bash),使用:

  • %HOME%%USERPROFILE%设置为“C:\用户\abc”
  • %PATH%设置为:
set PATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\
set "GH=C:\Program Files\Git"
set "PATH=%GH%\bin;%GH%\cmd;%GH%\usr\bin;%GH%\mingw64\bin;%GH%\mingw64\libexec\git-core;%PATH%"
  • 未设置SSH环境变量(使用set|grep -i ssh检查)

然后从相同的CMD会话重试,再次不使用bash。

相关问题