The issue as exposed here is solved (about files modes of the .ssh folder.

But an other issue persists so I create a new question : > Unable to login with SSH-RSA key

I can no longer connect with ssh-rsa key for a specific user, but it still work for other users.

The git user defined as follow :

# cat /etc/passwd | grep git

So you noticed that this is the git user thus its home is /var/git, it's not in /home.

Now, ssh always prompt me for password :

$ ssh git@srv
git@srv's password:

I checked logs :

# tail -n 1 /var/log/auth.log
[...] Authentication refused: bad ownership or modes for file /var/git/.ssh/authorized_keys

So authorized_keys as some ownership or modes missconfiguration. I don't understand because here is the conf for this file :

# ls -l /var/git/.ssh/ | grep auth
-rw-rw-r-- 1 git git 394 mai   22 17:39 authorized_keys

And here is (in case...) the parent .ssh dir:

# ls -al /var/git/ | grep ssh
drwxrwxr-x  2 git  git  4096 mai   22 17:39 .ssh

And the $HOME directory :

# ls -l /var/ | grep git
drwxr-xr-x  7 git  git    4096 mai   27 10:49 git

So owners are always git, like owner groups. And files are readable so where could be the trick ?

  • Does the .ssh directory actually require group-write access and on all of its files as well?
    – user86969
    May 27, 2015 at 10:02
  • 1
    @Nasha the exact oppposite - permissions here are too lax - as answered below by Otheus and damienfrancois. May 27, 2015 at 10:12
  • Well, I meant «as per your setup, can you consider restricting rights on the .ssh folder without impeding your installation?» BTW every file (with the exception of public keys) in the .ssh directory must (at least should) be read/write-able by the owner only, no access to group/others.
    – user86969
    May 27, 2015 at 11:16

3 Answers 3


The problem is the fact that file and directory permissions do not meet the requirements of StrictModes, which in OpenSSH is yes by default and should not be changed. Try setting the permissions of authorized_keys to 0600 and the .ssh directory to 0700.

# chmod 0700 .../.ssh/
# chmod 0600 .../.ssh/authorized_keys

Note that the ... will differ based on installation (e.g., in this question it is /var/git/ but for users it will be /home/username/.

  • Nope that's not it. authorized_keys and .ssh may be world-readable and ssh will work.
    – Otheus
    May 27, 2015 at 9:58
  • 2
    only if owned by root May 27, 2015 at 9:59
  • It applies to any user. At least in v 5.3p1
    – Otheus
    May 27, 2015 at 10:00
  • 2
    Connect with ssh -vv. That might provide you a hint why the public/private key authentication is failing.
    – Otheus
    May 27, 2015 at 10:12
  • 4
    Something useful is to start sshd in debug mode on the target machine with (from my memory so maybe not 100% accurate) /usr/sbin/sshd -d -e -p 1234 so you have a sshd server listening on port 1234 with all info spit out in the console. May 27, 2015 at 10:12

For reasons of paranoia, the .ssh directory and authorized_keys must not be group-writable. I guess the thinking is, the user must be the only one with explicit control over his/her authorization. I believe a work-around for this lies with ACL. The other work around is StrictModes=no setting in sshd's configuration file. But it would be too dangerous to do that for the sake of one user.

P.S. your ls -l /var | grep git is more concisely done as ls -ld /var/git

  • 1
    I can change out your entire .ssh directory with mine if group writable would be allowed on HOME, or .ssh. That is not paranoia but a considerable risk.
    – YoYo
    Sep 29, 2015 at 3:10
  • 1
    Anytime permissions for a user's home dir are set to group-writable, it's a considerable risk. But there are times when we know exactly what we're doing. It pisses me off the SSH team seems to assume the user doesn't.
    – Otheus
    Oct 7, 2015 at 9:28

The $HOME/.ssh directory mode must be 700 and authorized_keys should be readable by the owner only, i.e. mode 600:

chmod u=rwx,g=,o= /var/git/.ssh
chmod u=rw,g=,o= /var/git/.ssh/authorized_keys

As to the private key, it must be read-write-able by the owner only:

chmod u=rw,g=,o= /var/git/.ssh/id_?sa
  • What version are you running, Nasha? Have you actually tested this? That is, have you tested that og must not be read-execute?
    – Otheus
    May 27, 2015 at 10:10
  • I'm using ssh-server-6.2p2 on Mint. Works the same on Gentoo. I've been using this setup for quite some time without a problem. My SSH server runs as root BTW.
    – user86969
    May 27, 2015 at 11:03
  • 1
    @Otheus me --> /facepalm/ :-D Sometimes you can't spot the wrong bit looking too closely at it...
    – user86969
    May 27, 2015 at 11:22
  • 3
    Actually 700 and 600 are safest way to do. However 660 might work: if the user's group has no other users in it! I learnt it the hard way, the working login was denied after I added another user to the group, lol.
    – fchen
    Jan 8, 2018 at 4:48
  • 2
    @lol I also saw exactly this and it got me puzzled... I added a new user to the user's group, and suddenly authorized_keys-based authentication stopped working. If someone could locate information about this behaviour in the documentation, it would be great. Jul 17, 2019 at 8:02

Not the answer you're looking for? Browse other questions tagged .