SSH "Bad owner or permissions on .ssh/config"
This message means ssh refused to read a client configuration file because of
who owns it or who can write to it. Because the file was not read, none of its
Host entries applied, and ssh did not start a connection using
them. The message says nothing about the server, the network or your keys: it
comes from the machine you typed the command on.
This page describes standard OpenSSH behaviour. The commands are the usual ones, and wording differs between versions, distributions and platforms. We did not run them on your system for this page.
What the message means
Bad owner or permissions on /home/you/.ssh/config
OpenSSH reads its client settings from your own config file, usually
~/.ssh/config. Before it uses that file, or a file it pulls in
with an Include line, it checks the file. The general rule is
that the file should be owned by you (the user running ssh) or by root, and
that group and other users must not be able to write to it. If either part
fails, ssh reports this message and stops instead of using the file.
The rule is about writing, not about one particular number. A mode that is stricter than you need, or one that other users can read but not write, is not what this check is about. What it rejects is a file that someone other than you could change, because a config file can name commands that ssh would run.
This is a different message from the ones that sound alike, so confirm that first:
-
WARNING: UNPROTECTED PRIVATE KEY FILE!is about a private key file that other users can read, not about the config. It is covered in SSH "Permission denied (publickey)". -
Authentication refused: bad ownership or modesis written by the server in its log, about a home directory,.sshfolder orauthorized_keysfile on the device. It is also covered on the publickey page. - Failed to add the host to the list of known hosts is about a known_hosts file ssh could not write, not a config file it would not read.
- Bad configuration option means ssh did read the config and rejected one keyword in it, such as a typo or an option only a newer client knows.
- Permission denied (publickey) means a connection was made and login failed.
- Could not resolve hostname, a timeout or a refused connection and a closed handshake all happen later, when ssh is already trying to reach a machine.
1. See which file the message names
Read the path at the end of the message. Most often it is
.ssh/config in your home directory. It can also be a file in a
folder such as .ssh/config.d when your config uses an
Include line. The same check applies to each of them, and the one
to fix is the one named, not only config.
Running again with -v shows which files ssh is reading, and the
ssh -v output reader can check a pasted log
for this message. It runs in your browser and sends nothing.
ssh -v user@server.example.com
2. Check the owner and the write bits
List the file with its owner and mode, using the path from the message:
ls -ld ~/.ssh/config
id -un
In the first line of output, the third column is the owner and the first
column is the mode, such as -rw-r--r--. The second command prints
your user name. You are looking for two things:
-
The owner is your user name, or
root. Another user's name here is a problem. -
In the mode, group and other have no
w. A mode such as-rw-rw-r--(group can write) or-rw-r--rw-(other can write) is the problem. Reading by others is not what this check rejects.
If the line shows a mode where group or other can write, or an owner that is neither you nor root, that explains the message.
3. Fix the owner and the mode
Removing write access for group and others leaves the rest of the mode as it was:
chmod go-w ~/.ssh/config
If the owner is wrong, give the file to yourself. This usually needs administrator rights, because you cannot normally take over a file that belongs to someone else:
sudo chown "$(id -un)" ~/.ssh/config
Many people also choose to make the file readable only by themselves, with
chmod 600. That is a reasonable habit for a file that may name
hosts and users, but it is a choice. The check described here is about group
and other write access, so a mode that is not writable by them is not rejected
by this message.
If the file was changed by someone or something else, think about why before you change it back: a config file that another account can write is one that account can use to change what ssh runs for you.
Common causes
- The file was copied or unpacked from another machine, a USB stick or an archive, and kept the owner or mode it had there, or gained group write from the way it was created.
- A home directory was shared, restored from a backup or moved to a new account, so the files belong to a user that no longer matches yours.
- The file was edited or created with elevated rights, so it is now owned by root or another account. Root as owner is accepted, but an account that is not you is not.
-
The file is on a drive or share that does not keep Unix owners and modes in
the usual way. Then
chmodandchownmay appear to do nothing. Copying the file into your home directory on a normal Linux or macOS file system and using that copy is a simple way to check.
None of these is certain for your machine. The listing in step 2 is what shows the actual state.
4. Retry the same command
Run the same ssh command again. If the file is now readable by
ssh, its Host entries apply, and you may see a different message
than before. That is progress: whatever comes next is the next problem, and
one of the guides above covers it. If it names a different file, repeat steps
2 and 3 for that file.
ssh -G reads the same configuration files, so it can show the
same refusal until the file is fixed. After that, it prints the values ssh
would use for a host, and the
ssh -G output reader shows them from a
pasted copy. It runs in your browser and sends nothing.
ssh -G myserver | grep -i -E '^(hostname|user|port|identityfile) '
If the machine is a RescueShell device
A path that starts from the device can avoid a public SSH port. The agent on the device keeps an outbound HTTPS connection to our relay, so reaching a shell does not depend on an inbound port on the device. That needs the agent installed and running first.
It does not repair a local client config that ssh will not read. If you still use that file for a direct connection, the owner and mode checks above still apply to it. If a shell does not open once the agent is installed, see the shell does not open.
Try it on one device
The first device is free to try with no card, for 30 days from when it connects, not from when you sign up. Start a trial.