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
I needed to have rw for user only permissions on config. This fixed it.
As others have noted below, it could be the file owner. (upvote them!)
If your whole folder has invalid permissions here's a table of possible permissions:
id_rsa
) (code)config
id_rsa.pub
)authorized_keys
(code)known_hosts
Sources:
These commands should fix the permission problem:
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:For me it was an issue with my user account not being the owner of the file
If on Windows Subsystem for Linux (WSL) and you pointed your WSL home directory to your Windows home directory (not recommended!) then chmod has no effect. Before you can
chmod
the files mentioned in other answers you must addto your
/etc/wsl.conf
then restart WSL (requires build 17093 or later).Before mount says:
After mount says:
Don't forget about the group:
:-)
I met this issue on windows 10 with
vagrant ssh
. And tried all the above methods, but get no luck. Finally I deleted that ssh config file and then it works!