22

Git suddenly stopped working for me. (I use Git Bash under Windows 7. I am not using 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 various SO questions.

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?

6
  • Do you use Cygwin? Commented Mar 15, 2016 at 12:19
  • @mauro, no, I don't. Commented Mar 15, 2016 at 12:22
  • As a temporary solution I created symlink for c:\Program Files\Git\home\ <<===>> c:\Users. Commented Mar 15, 2016 at 12:25
  • mkdir /home/sigod/.ssh might help Commented Sep 14, 2016 at 6:24
  • 1
    Git should be using your home directory, which should be configured by the operating system. Presumably /home/sigod does not exist (or is not a directory), but something in your environment is telling git that that's your home directory. Even under Linux, the home directory for user sigod is not necessarily /home/sigod; the home directory for a user is set by the entry in /etc/passwd, which is used to set the $HOME environment variable, which is what git looks at. It probably works differently under Windows. Perhaps a Windows expert can help. Commented Jun 6, 2018 at 21:31

7 Answers 7

12

Git Bash is built using MSYS2, which is a very close cousin to CygWin. The following steps might just work for your case:

  1. Open cmd.exe as administrator, and set the HOME system environment variable to point to your user directory.

    setx -m HOME ^%UserProfile^%
    

The above command will set HOME=%UserProfile% for your system environment.

  1. Open git bash, and make sure that /etc/nsswitch.conf file contains an uncommented db_home line entry. Make sure it matches one of the below configurations:

    option a:

    db_home: env windows cygwin desc
    

    option b:

    db_home: windows
    
  2. 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).

I based the above on an answer explaining the CygWin version of the same question.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks for the correction. modified my answer. btw github.com/git-for-windows/git/wiki/FAQ
1

GitBash is similar to Cygwin which uses traditional linux permissions.

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:

mkdir ~/.ssh
chown $USER:$USER -R ~/.ssh

then run stat ~/.ssh to see that the permissions changed correctly

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.

You can change your linux HOME by modifying ~/.bashrc and adding the line export HOME=/some/directory

You can see how your GitBash filesystem corresponds to your windows filesystem by typing the command 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

3 Comments

Thank you for detailed response. Unfortunately, I cannot test it, as the problem disappeared along with symlink.
In my case the owner was correct but there was a permissions issue. A blanket chmod -R 777 .ssh fixed the issue (and a subsequent issue with writing to the known_hosts file) - but would of course strongly recommend taking a backup of the existing .ssh folder for anyone doing this.
@SteveChambers hi, thanks for bringing this issue to my attention. I would strongly advise against chmod -R 777 .ssh as this enables any visitor or guest to your computer to see your private ssh keys. Instead I would simply add -R to my command to make it recursive. I've update my answer to reflect this. Regarding the permissions in your .ssh folder I suggest running chown $USER:$USER -R ~/.ssh to make yourself the owner and fixing the permissions with : chmod 644 -R ~/.ssh chmod 700 ~/.ssh chmod 600 ~/.ssh/id_rsa
1

Make sure which one [ssh.exe] you are executing ! $ where ssh

D:\xxxx\bin\ssh.exe
C:\Program Files\Git\usr\bin\ssh.exe
C:\Windows\System32\OpenSSH\ssh.exe

In my case, there is another ssh.exe in my export Path. (i.e.: D:\xxxx\bin\ssh.exe)

So I remove the the ssh.exe and keep the original one! (C:\Program Files\Git\usr\bin\ssh.exe)

Everything is nice now!

Comments

0

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.

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):

  1. Create this folder struture C:\Program Files\Git**home\carlos.leao**
  2. start CMD.exe
  3. run the comand: mklink /d "C:\Users\carlos.leao.ssh" "C:\Program Files\Git\home\carlos.leao.ssh"

Works like a charm!

Comments

0

Reinstalling git-bash worked for me.

Comments

0

Windows Machine

you can use cd ~/.ssh/ instead of ~/.ssh

cd ~/.ssh/

4 Comments

What difference would that make? What does this have to do with the question being asked?
Please add some explanation to your answer such that others can learn from it
no need to create the .ssh folder. by default, it has on windows or any other os, in Windows you just type ~/.ssh, will get an error. if you change the directory cd ~/.ssh/, it will navigate to .ssh folder on your machine
that so wierd i run 'ls -al' but not showing .ssh but if run cd ~/.ssh/ then enter .ssh.
-1
icacls C:\Users\101\.ssh\config /remove "NT AUTHORITY\Authenticated Users"
icacls C:\Users\101\.ssh\config /inheritance:r
icacls C:\Users\101\.ssh\config /remove "NT AUTHORITY\Authenticated Users"
icacls C:\Users\101\.ssh\config /grant:r 101:(R,W)
icacls C:\Users\101\.ssh\config /grant:r SYSTEM:(F)
icacls C:\Users\101\.ssh\config /remove "NT AUTHORITY\Authenticated Users"
icacls C:\Users\101\.ssh\config /grant:r 101:(R,W)
icacls C:\Users\101\.ssh\config /grant:r SYSTEM:(F)
takeown /F C:\Users\101\.ssh\config
Restart-Service sshd

2 Comments

It would be great to have an explanation of what any of this means.
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.