Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not create directory '/home/username/.ssh'

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?

like image 581
sigod Avatar asked Mar 15 '16 12:03

sigod


3 Answers

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.

like image 110
Miron Veryanskiy Avatar answered Oct 19 '22 07:10

Miron Veryanskiy


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

like image 1
yosefrow Avatar answered Oct 19 '22 09:10

yosefrow


Windows Machine

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

cd ~/.ssh/
like image 1
Najathi Avatar answered Oct 19 '22 08:10

Najathi