313

When I try to ssh to another box, I get this strange error

$ ssh hostname
Bad owner or permissions on ~/.ssh/config

But I made sure that I own and have rw permissions on the file:

ls -la ~/.ssh/
total 40K
drwx------ 2 robert robert 4.0K Mar 29 11:04 ./
drwx------ 7 robert robert 4.0K Mar 29 11:04 ../
-rw-r--r-- 1 robert robert 2.0K Mar 17 20:47 authorized_keys
-rw-rw-r-- 1 robert robert   31 Mar 29 11:04 config
-rw------- 1 robert robert 1.7K Aug  4  2010 id_rsa
-rw-r--r-- 1 robert robert  406 Aug  4  2010 id_rsa.pub
-rw-r--r-- 1 robert robert 6.1K Mar 29 11:03 known_hosts
490

I needed to have rw for user only permissions on config. This fixed it.

chmod 600 ~/.ssh/config

As others have noted below, it could be the file owner. (upvote them!)

chown $USER ~/.ssh/config
  • 18
    Sometimes it's not only the permissions, but also the owner that can cause the problem; in my case, I had to do this as well: chown -R robert:robert ~/.ssh – Nicolas C Jan 26 '15 at 12:27
  • 2
    In my case, going from 644 to 600 did the trick. – Magicsowon Oct 18 '16 at 18:15
  • 2
    Just read permission should be sufficient, i.e. 400 – 030 Jan 2 '17 at 0:06
  • 1
    For me, 600 didn't work, only 400 (on Ubuntu Xenial) – Martín Coll Oct 25 '17 at 0:35
  • @030 As long as you don't intend to edit the file.. – Sean the Bean Nov 16 '17 at 13:31
52

These commands should fix the permission problem:

chown $USER ~/.ssh/config
chmod 644 ~/.ssh/config

Prefix with sudo if the files are owned by different user (or you don't have access to them).

If more files are affected, replace config with *.

In man ssh we can read:

Because of the potential for abuse, this file must have strict permissions: read/write for the user, and not writable by others. It may be group-writable provided that the group in question contains only the user.

  • 2
    This did the trick for me. I am using cygwin and cygwin .ssh is symlinked to windows user .ssh. I had to run those commands in cygwin window. – Damodar Bashyal Apr 27 '16 at 5:54
10

For me it was an issue with my user account not being the owner of the file

sudo chown myuser ~/.ssh/config

protected by Community Jun 13 '18 at 6:31

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.