SSH "Bad owner or permissions on ~/.ssh/config": what it checks and how to fix it
ssh stops with Bad owner or permissions when ~/.ssh/config belongs to another user or is group or world writable. chmod 600 and chown to yourself fix it.
Bad owner or permissions on /home/user1/.ssh/config
The OpenSSH client printed this and stopped before it connected to anything. It found your personal configuration file, ~/.ssh/config, and refused to read it because someone other than you could have changed it. scp, sftp, git over SSH and anything else that runs ssh stop with the same line.
The server is not involved. Nothing on the host will clear this message.
The rule
Before reading the file, ssh checks two things:
- Owner. The file must belong to the account running
ssh, or toroot. - Write bits. Neither the group nor others may have write permission.
Read permission does not matter here. 600 (-rw-------) and 644 (-rw-r--r--) both pass. 664 and 666 fail, because the group or everyone can write. The ssh(1) manual states the rule as read/write for the user and not writable by others.
The same check runs on every file that ~/.ssh/config pulls in with an Include line, and on files that /etc/ssh/ssh_config includes. The system-wide /etc/ssh/ssh_config itself is not checked this way, and neither is a file you name with ssh -F.
Fix it
Look at the owner and mode first:
ls -l ~/.ssh/config
Then make the file yours and remove write access for everyone else:
chown user1 ~/.ssh/config
chmod 600 ~/.ssh/config
Use sudo chown if the file belongs to another account and you cannot change it yourself. If the message names an included file instead, run the same commands on that file.
While you are in ~/.ssh, the usual mode for the directory is 700. Private keys have a stricter rule of their own; see SSH "WARNING: UNPROTECTED PRIVATE KEY FILE!" and bad permissions.
Common causes
- The file is group writable. A umask of
002, or an editor or sync tool that creates files as664, adds group write.chmod 600removes it. - root uses another user's file. When
/root/.sshis a link to/home/user1/.ssh, or a container running as root has the host's~/.sshmounted, the file belongs touser1whilesshruns as root. That fails the owner rule. Give root its own copy of the config, owned by root, or pointsshat the file with-F /home/user1/.ssh/config, which skips this check. - Windows drives in WSL. Files under
/mnt/cshow permissions calculated from Windows, the same for user, group and others, unless the drive is mounted with themetadataoption. A config file there usually looks writable by everyone andchmodmay not change it. Keep~/.sshin the Linux home directory instead. - Network shares and USB drives. File systems that do not store Unix owners and modes, such as FAT, exFAT and many SMB shares, can show every file as writable by all. Keep the config on a local disk.
On Windows
The OpenSSH client built into Windows checks the file's access list instead of mode bits, and prints the same message with a Windows path, for example Bad owner or permissions on C:\Users\user1/.ssh/config. The owner must be your own account, SYSTEM or the Administrators group. No other account may have write access; read access for others is allowed. In the file's Properties, open Security, then Advanced, make yourself the owner, and remove write permissions for other users and groups, including inherited entries.
Messages that look similar
WARNING: UNPROTECTED PRIVATE KEY FILE!is about a private key, not the config file. A key fails if others can even read it. See SSH "WARNING: UNPROTECTED PRIVATE KEY FILE!" and bad permissions.Authentication refused: bad ownership or modesappears in the server's log and is about the host's~/.sshandauthorized_keys. See Authorized keys and permissions.bad ownership or modes for chroot directoryis an SFTP server setting. See SFTP chroot: bad ownership or modes for chroot directory.
Related
- The ssh config file
- SSH "WARNING: UNPROTECTED PRIVATE KEY FILE!" and bad permissions
- Authorized keys and permissions
- Do scp and sftp use ~/.ssh/config?
- SSH error messages, what each one means
- SSH "Bad configuration option" in ~/.ssh/config or sshd_config