11

I am trying to clone a repository, but I am getting an error

Could not create directory '/c/Windows/system32/config/systemprofile/.ssh'. The authenticity of host '(host here)' can't be established. 

I am running Windows 7 and using tortoiseGit. I have generated a ssh key and added it to server. Any suggestions what am I doing wrong?

2
  • You are running git as the SYSTEM user. Why? Commented Jul 1, 2013 at 10:13
  • try to run got bash with elevated privs once and clone from there. This prompt probably is part when ssh asks to type yes to add host fingerprint Commented Jul 1, 2013 at 10:24

3 Answers 3

17

Just ran into this issue and wanted to post the solution.

When using a CYGWIN version of SSH you need to create an environment variable called HOME. If you create HOME as a System variable and set it to %USERPROFILE%, and cmd/bash gets launched as system (elevated), your %HOME% path will be C:\Windows\System32.

An easy fix is to hardcode your userprofile path C:\Users\username to the HOME system variable, however if you have multiple users you will need to create environment variables accordingly.

I was not implicitly launching cmd as SYSTEM however I was having this problem and not sure why. Safest option would be to only have a user environment variable called %USERPROFILE% and to not use an elevated command prompt.

If you're having this issue then run ECHO %HOME% and you'll see what the variable is being read as (or if it exists).

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

1 Comment

Yer a saint ... spent too much time wondering if I just couldn't git bash on windows cause I never dealt with a program that incorrectly set the %HOME% variable ... was staring me straight in the face entire time!!
3

I was using SSH to clone a git repo with Windows; however in PowerShell.

$configStoreGitDir = "$GitBaseDir\.git" if (!(Test-Path -Path $configStoreGitDir -PathType Container)) { Write-Verbose "Unable to locate local git folder at $GitBaseDir - recreating and cloning" New-Item -Type Directory $GitBaseDir git clone $GIT_REPO $GitBaseDir } 

When I was trying to clone a repo as a user I was getting the same .ssh directory error:

Cloning into 'C:\Git\test-environments'... Could not create directory '/c/Windows/system32/.ssh'. 

Instead of hardcoding the path, I set the Powershell environment variable $env:USERPROFILE to use HOME just like @akevit mentioned in his answer.

$env:HOME = $env:USERPROFILE $configStoreGitDir = "$GitBaseDir\.git" if (!(Test-Path -Path $configStoreGitDir -PathType Container)) { Write-Verbose "Unable to locate local git folder at $GitBaseDir - recreating and cloning" New-Item -Type Directory $GitBaseDir git clone $GIT_REPO $GitBaseDir } 

Now it works and uses the known_hosts and id_rsa private key in the users $env:USERPROFILE\.ssh\ directory.

Cloning into 'C:\Git\test-environments'... remote: Counting objects: 460, done. remote: Compressing objects: 100% (457/457), done. 

This was with the latest Windows 64bit git install:

git --version git version 2.6.3.windows.1 

2 Comments

In short, when using powershell, enter $env:HOME = $env:USERPROFILE
In 2021 with ps 5 up, $env:HOME seems to be split to $env:HOMEdrive and $env:HOMEpath
1

Just add HOME variable with C:\Users\username value under User Variables

Click here to see sample image

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.