windows 无法创建目录“/home/username/.ssh”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36011084/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Could not create directory '/home/username/.ssh'
提问by sigod
Git suddenly stopped working for me. (I use Git Bash under Windows 7. I am not using Cygwin.)
Git突然停止对我来说有效。(我在 Windows 7 下使用 Git Bash。我没有使用 Cygwin。)
Every time I try to pull or push it says:
每次我尝试拉或推它时都会说:
Could not create directory '/home/sigod/.ssh'
My SSH keys located in C:\Users\sigod\.ssh
and HOME
set to /c/Users/sigod
. Which should work according to variousSOquestions.
我的 SSH 密钥位于C:\Users\sigod\.ssh
并HOME
设置为/c/Users/sigod
. 哪个应该根据各种SO问题工作。
If I place SSH keys into C:\Program Files\Git\home\sigod\.ssh
then Git starts working again. But how can I make it work without dirty solutions?
如果我将 SSH 密钥放入,C:\Program Files\Git\home\sigod\.ssh
那么 Git 将再次开始工作。但是我怎样才能让它在没有肮脏解决方案的情况下工作呢?
回答by Miron V
Git Bash is built using MSYS2, which is a very close cousin to CygWin. The following might just work for your case, follow these steps:
Git Bash 是使用 MSYS2 构建的,它是 CygWin 的近亲。以下可能仅适用于您的情况,请按照以下步骤操作:
Open cmd.exe as administrator, and set the HOMEsystem environment variable to point to your user directory.
setx -m HOME ^%UserProfile^%
The above command will set HOME=%UserProfile%for your system environment.
Open git bash, and make sure that /etc/nsswitch.conffile contains an uncommented db_homeline entry. Make sure it matches one of the below configurations:
option a:
db_home: env windows cygwin desc
option b:
db_home: windows
Fully close git-bash when trying out options in step 2 (to be sure no background processes are keeping git-bash alive, log off from windows and log back in).
以管理员身份打开 cmd.exe,将HOME系统环境变量设置为指向您的用户目录。
setx -m HOME ^%UserProfile^%
上述命令将为您的系统环境设置HOME=%UserProfile%。
打开 git bash,并确保/etc/nsswitch.conf文件包含未注释的db_home行条目。确保它匹配以下配置之一:
选项一:
db_home: env windows cygwin desc
选项b:
db_home: windows
在第 2 步中尝试选项时完全关闭 git-bash(确保没有后台进程使 git-bash 保持活动状态,从 Windows 注销并重新登录)。
I based the above on an answer explaining the CygWin version of the same question.
回答by yosefrow
GitBash is similar to Cygwin which uses traditional linux permissions.
GitBash 类似于 Cygwin,后者使用传统的 linux 权限。
I suggest you make sure your ssh directory exists in the correct place and has the right permissions by running from git bash the following commands:
我建议您通过从 git bash 运行以下命令来确保您的 ssh 目录存在于正确的位置并具有正确的权限:
mkdir ~/.ssh
chown $USER:$USER -R ~/.ssh
then run stat ~/.ssh
to see that the permissions changed correctly
然后运行stat ~/.ssh
查看权限是否正确更改
ls ~/.ssh
to see that your key is properly installed in the correct place.
查看您的密钥是否正确安装在正确的位置。
You can see which directory is actually registered as your home directory by running echo ~
or echo $HOME
.
您可以通过运行echo ~
或来查看哪个目录实际注册为您的主目录echo $HOME
。
You can change your linux HOME by modifying ~/.bashrc
and adding the line export HOME=/some/directory
您可以通过修改~/.bashrc
和添加行来更改您的 linux HOMEexport HOME=/some/directory
You can see how your GitBash filesystem corresponds to your windows filesystem by typing the command mount
您可以通过键入命令来查看 GitBash 文件系统与 Windows 文件系统的对应关系 mount
MINGW64 /c $ mount
C:/Program Files/Git on / type ntfs (binary,noacl,auto)
C:/Program Files/Git/usr/bin on /bin type ntfs (binary,noacl,auto)
C:/Users/MyUser/AppData/Local/Temp on /tmp type ntfs (binary,noacl,posix=0,usertemp)
C: on /c type ntfs (binary,noacl,posix=0,user,noumount,auto)
D: on /d type ntfs (binary,noacl,posix=0,user,noumount,auto)
If nothing else works, you can also try modifying the %HOME%
environment variable in windows to make sure it directs to the right path. But any windows env var will be overwritten by linux vars you add to your ~/.bashrc
如果没有其他效果,您也可以尝试%HOME%
在windows中修改环境变量以确保它指向正确的路径。但是任何 windows env var 都会被你添加到你的 linux vars 覆盖~/.bashrc
回答by Carlos Augusto Le?o
Same thing here: Could not create directory '/home/carlos.leao/.ssh', in Git Bash for Windows, version 2.17.1.2-64-bit. Using Windows 10.
同样的事情:无法在 Git Bash for Windows 版本 2.17.1.2-64 位中创建目录“/home/carlos.leao/.ssh”。使用 Windows 10。
Solve with sigod workaround. But insted of create the folder struture C:\Program Files\Git\home\carlos.leao and copied the folder C:\Users\carlos.leao.ssh into it i've created a symbolic link from C:\Users\carlos.leao.ssh to C:\Program Files\Git\home\carlos.leao.ssh. To do it (replace carlos.leao with your Windows username):
用 sigod 解决方法解决。但是创建文件夹结构 C:\Program Files\Git\home\carlos.leao 并将文件夹 C:\Users\carlos.leao.ssh 复制到其中我已经从 C:\Users\carlos 创建了一个符号链接.leao.ssh 到 C:\Program Files\Git\home\carlos.leao.ssh。要做到这一点(用您的 Windows 用户名替换 carlos.leao):
- Create this folder struture C:\Program Files\Git**home\carlos.leao**
- start CMD.exe
- run the comand: mklink /d "C:\Users\carlos.leao.ssh" "C:\Program Files\Git\home\carlos.leao.ssh"
- 创建此文件夹结构 C:\Program Files\Git**home\carlos.leao**
- 启动 CMD.exe
- 运行命令: mklink /d "C:\Users\carlos.leao.ssh" "C:\Program Files\Git\home\carlos.leao.ssh"
Works like a charm!
奇迹般有效!