SSH could not create directory /home/USERNAME/.ssh

7

5

My script is executing the below command:

command = os.system('rdiff-backup --exclude "**.dropbox**" --exclude "**.ini**" --remote-schema "ssh -o UserKnownHostsFile=/cygdrive/c/Users/Adam/.ssh/known_hosts -i /cygdrive/c/Users/Adam/.ssh/id_rsa %s -p1019 rdiff-backup --server" C:/Users/Adam/Dropbox pi@192.168.0.5::/mnt/disk1/Adam/Dropbox')

As you can see, I have told it where to look for the known_hosts folder and told it where the key was - without these two questions I would be constantly asked about adding my server to known_hosts each and every execute and be required to enter the password, for each and every execute. It's a shame SSH couldn't locate these independently, my assumption is that it always worked from the same directory, C:\Users\Adam\.ssh?

Anywho, the only error message I get now is Could not create directory '/home/Adam/.ssh' - I've ensured my HOME variable for my current User is correct but it still can't seem to find the .ssh folder. The script executes no problem, it's just this annoying error message. I'm using the SSH package from Cygwin, I'm not sure how important this is? Also, I generated the .ssh directory using Rsync's ssh.exe file, not Cygwin's. Is this important?

adampski

Posted 2014-03-31T11:15:31.880

Reputation: 1 164

Answers

11

I found the answer to my solutions in this blog post.

"First locate the file called passwd in your C:\path\to\cygwin\etc directory and open it with wordpad. Second, replace the text /home/YOUR_NAME with /cygdrive/c/Documents and Settings/YOUR_NAME Finally, save the file."


Update

Some people have reported that adding %USERPROFILE% as a value to a system variable called "HOME" works.

adampski

Posted 2014-03-31T11:15:31.880

Reputation: 1 164

"Access to C:\cygwin\etc\passwd was denied" (also tried as admin). Edit: Made myself owner and gave myself permission. Works now – etherous – 2015-02-10T02:37:15.513

4I'm having the same problem, but I can't find the passwd file – Moha the almighty camel – 2015-12-10T14:07:21.847

2I guess you could generate one. "mkpasswd -l >/etc/passwd". Execute that in Cygwin bash terminal, not cmd. – adampski – 2015-12-10T14:34:04.520

2generated passwd file using mkpasswd, replaced mentioned text to new one, problem still exist: can't find path /home/USER/.ssh – maks – 2016-01-13T15:38:22.967

1Adding a HOME variable in the path resolved the issue for me. HOME: C:\yourusername – Midhun VP – 2017-07-22T14:57:03.873

For me, manually creating a C:\path\to\cygwin\home<USERNAME> directory did the trick. – NVM – 2017-11-20T06:55:58.863

Windows 10 here, use /cygdrive/c/Users/USERNAME instead of /cygdrive/c/Documents and Settings/YOUR_NAME, worked for me. – Jason Goal – 2020-02-06T21:45:21.313

2

For those 2019 tumbleweeds if you've tried everything here and nothing works if your nssswitch.conf file has:

db_home: windows

In a Cygwin terminal running in admin mode try:

export CYGWIN=winsymlinks:native
mkdir -p /home/$USER
ln -s $HOME/.ssh /home/$USER

Additional Details

In 2015 Cygwin stopped creating a /etc/passwd file by default:

Cygwin can now generate passwd/group entries directly from Windows user databases (local SAM or Active Directory), thus allowing to run Cygwin without having to create /etc/passwd and /etc/group files. Introduce /etc/nsswitch.conf file to configure passwd/group handling.

For bordercase which require to use /etc/passwd and /etc/group files, change mkpasswd/mkgroup to generate passwd/group entries compatible with the entries read from SAM/AD.

From https://github.com/Alexpux/Cygwin/blob/master/winsup/cygwin/release/1.7.34#L4-L11

As stated above mkpasswd command and the etc/passwdfile was a way of 'connecting' with Windows Active Directory.

If you are using a company computer using Active Directory sometimes somewhere along the line Active Directory and/or Cygwin fail to communicate and you end up loosing the entry that controls where the HOME directory is set. To test this run mkpasswd and check if your username shows up in the list.

After running mkpasswd and you don't see your username, by default, Cygwin's ssh will search for the .ssh folder in /home/$USER/.ssh. That directory won't exists if you setup Cygwin with db_home: windows which points the HOME directory to C:\Users\$USER. So the above commands fix this by:

# Use windows native symlinks (only works in while running as admin)
export CYGWIN=winsymlinks:native

# Create missing directory structure (C:\[Cygwin install directory]\home\$USER)
mkdir -p /home/$USER

# Link C:\User\$USER\.ssh -> C:\[Cygwin install directory]\home\$USER\.ssh
ln -s $HOME/.ssh /home/$USER

These commands are a hack and the real solution would involve figuring out why mkpasswd is failing to create a entry for the user. However, that would probably involve digging into both Active Directory and Cygwin :(.

ksrb

Posted 2014-03-31T11:15:31.880

Reputation: 121

0

I had the same problem and already had my $HOME set to %USERPROFILE%. This is what worked for me:

Change the the line in the file /etc/nsswitch.conf to:

db_home: windows cygwin desc

(From this answer)

TT--

Posted 2014-03-31T11:15:31.880

Reputation: 202

-1

As per @MidhunVP suggestion, this error was triggered for me some time later after I had removed the HOME environment variable.

Control Panel > Edit Environment Variables > New...

Variable Name:  HOME
Variable Value: C:\Users\YOUR_NAME

EoghanM

Posted 2014-03-31T11:15:31.880

Reputation: 219