"Bad owner or permissions" error using Cygwin's ssh.exe

After doing as above, I always got this:

total 22
drwxrwxr-x+ 1 jl None    0 Sep  9 18:44 .
drwxrwxr-x+ 1 jl None    0 Sep  9 18:44 ..
-rw-rw----  1 jl None  129 Jul  1 14:30 config

and the error on .ssh/config. So I've run chown on the .ssh folder, and chmod again like this:

> chown -R [USERNAME]:users .ssh/

and then:

> chmod -R 600 .ssh/

and finally I got it working:

total 29
drwxrwxr-x+ 1 jl None     0 Sep  9 18:44 .
drwxrwxrwt+ 1 jl None     0 Sep  9 18:44 ..
drw-------+ 1 jl Users    0 Sep  9 18:44 .ssh

Edit(for bash on Windows10)

When you get the error..

Failed to add the host to the list of known hosts (/PATH_TO_HOME/USERNAME/.ssh/known_hosts).

Make sure that known_hosts is writable

$ chmod 755 known_hosts

Note: I believe you only need to set 600 for your private key

Then, try to ssh.

When you get..

Permanently added 'HOST_IP' (RSA) to the list of known hosts.

You may replace mode 600

$ chmod 600 known_hosts

P.S.: I think this is a bug on Windows 8.


This answer is copied verbatim from https://superuser.com/a/875934/82032. This is the only answer that worked for me after a recent cygwin upgrade.

Don't forget the ACLs

Nothing worked for me until I stripped the file of ACLs and reset the permissions.

#remove ACLs
setfacl -b ~/.ssh/config

#reset permissions
chmod 0600 ~/.ssh/config

You can use getfacl to view the current ACL on a file.

getfacl ~/.ssh/config

Before I removed the ACLs (Broken):

# owner: Administrators
# group: None
user::rw-
group::---
group:Authenticated Users:rwx
group:SYSTEM:rwx
mask:rwx
other:---

After: (working)

# file: config
# owner: myusername
# group: None
user::rw-
group::---
other:---

For unix & OSX

Quite simply:

chown -R $USER:users ~/.ssh/
chmod -R 600 ~/.ssh/

For Windows

If the file is a windows (NTFS) symbolic link, the above won't work. You need to make it a regular file. I am not sure why.

If you don't have openssh or cygwin, use chocolatey to install it easily.

choco install cyg-get

Open Cygwin Terminal that was installed with chocolatey and run (note that ssh-keygen creates new keys):

cyg-get install openssh
ssh-keygen
cd ~/.ssh && explorer.exe .

Verify keys are there (or replace them with the keys you want), and then in Cygwin shell:

chown -R $USER:users ~/.ssh/
chmod -R 600 ~/.ssh/

Or for the rare case that you're using (and generated the keys from) chocolatey's SSH package:

chown -R $USER:users  /cygdrive/c/Users/$USER/.ssh
chmod -R 600 /cygdrive/c/Users/$USER/.ssh