20

I have realized that I am no longer able to connect to the webserver at x.x.202.50. Yesterday I have changed the following ssh configuration file: /share/homes/admin/.ssh/config by adding the following settings:

# ssh (secure shell) configuration file
Host webserver
    HostName x.x.212.50
    User user1
    IdentityFile ~/.ssh/id_rsa `

The reason I did this is to enable key login for synchronization purpose (with Unison).

Now, when I try to connect to the server I receive the following error:

Bad owner or permissions on /share/homes/admin/.ssh/config

I make the connection with Putty from Windows 10 and from Linux server to another Linux server.

I need to connect to the server because I am involved in a project, and I don't know how to do it. Does anybody know how to do this?

2
  • 7
    chmod 600 /share/homes/admin/.ssh/config should fix it. This gives the owner rw permissions and nobody else.
    – Magnus
    May 24, 2017 at 12:16
  • Could you run ls -ld /share/homes/admin/.ssh /share/homes/admin/.ssh/config and edit your question to include the output?
    – Kenster
    May 24, 2017 at 13:02

4 Answers 4

23

The general rule for the files that can affect the security (private keys, configuration files, authorized keys) is that they should not be writable by anyone else than the owner (the private keys should not be accessible!).

The error is coming from the openssh code below:

if (((sb.st_uid != 0 && sb.st_uid != getuid()) ||
    (sb.st_mode & 022) != 0))
      fatal("Bad owner or permissions on %s", filename);

So translating it to the English, means that the config file must be owned by root or by the user running the ssh and can not be writable by any group or other users.

As already pointed out in the comments, you probably gave this permissions to somebody somehow so removing these permissions should fix that problem:

chmod go-w /share/homes/admin/.ssh/config
3
  • 1
    Also, .ssh should have similar persmissions (and maybe also .ssh/.. which, in this case, is admin).
    – TOOGAM
    May 25, 2017 at 3:20
  • That's what solved my issue. Thank you @Jakuje.
    – sk001
    Aug 3, 2021 at 23:19
  • What about for github commands?
    – geoidesic
    Sep 5 at 9:00
17

You need to change the permissions of .ssh directory. Run the following, (I found 600 will not fix it on its own):

chmod 700 ~/.ssh
chmod 600 ~/.ssh/*
2
  • 1
    It helped me a lot, thanks! I just changed my computer and did a copy of the ssh folder, but didn't work good. The problem was the access right. Great! Aug 8 at 14:51
  • You can simply use chmod -R to recursively modify permissions of all files in a folder. 2 days ago
1

If your home directory is mounted on NFS and there is an NFS problem or a Domain login problem, it could be that the ~/.ssh/config file is owned by nobody (temporarily, until the NFS or Domain loging problem is fixed). This doesn't fix your problem, but the problem may not be with the permissions. Just do ls -la on the directory and make sure the files are still yours. And if you see nobody, time to send an email to IT.

0

The other answers only solve the problem if there is a wrong permission. However, in my case the problem was a wrong file owner. You can run ls -l ~/.ssh to view the information about permissions and owners. File owner can be seen in the 3rd column. If it is wrong, execute:

chown <newOwner> <fileName>

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