Strovent SystemsSign in
Reference

SSH "WARNING: UNPROTECTED PRIVATE KEY FILE!" and bad permissions

ssh ignores a private key that other users can read and prints UNPROTECTED PRIVATE KEY FILE and Load key bad permissions. chmod 600 on the key fixes it.

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0644 for '/home/user1/.ssh/id_ed25519' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
Load key "/home/user1/.ssh/id_ed25519": bad permissions
[email protected]: Permission denied (publickey).

The OpenSSH client printed this on your side, before the key was ever sent. The key file can be read by other accounts on the same computer, so ssh refuses to use it. It then tries any other login methods, and the "Permission denied" at the end is the result of skipping the key.

The server's settings are not involved. Changing anything on the host will not clear this warning.

The rule

On Linux, macOS and other Unix systems, the check applies to a key file owned by the account running ssh. If any permission bit is set for the group or for others, the key is ignored. The number in the message is the file's current mode: 0644 means the owner can read and write, and everyone else can read.

The ssh(1) manual says the private key files should be readable by the user and not accessible by others, and that ssh ignores a private key file that others can access.

Fix it

chmod 600 ~/.ssh/id_ed25519

600 leaves read and write for you only. 400 (read only, for you) also works. Use the path from the message, which is not always under ~/.ssh, for example a .pem file in Downloads.

While you are there, the recommended mode for the ~/.ssh directory is 700. The public key (.pub) may stay readable, 644 is fine.

If ls -l shows that the file belongs to another account, for example root after a copy with sudo, give it back to yourself first:

sudo chown user1 ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519

When chmod does not stick

  • Windows drives in WSL. Files under /mnt/c show permissions calculated from Windows, the same for user, group and others, unless the drive is mounted with the metadata option. A key there looks open to everyone and chmod may not change it. Copy the key into the Linux home directory, for example ~/.ssh inside WSL, and run chmod 600 there.
  • USB sticks and network shares. File systems such as FAT and exFAT, and many shares, do not store Unix permissions. Copy the key to your home directory first.

On Windows

OpenSSH for Windows uses the file's access list instead of mode bits, so the message reads Permissions for 'C:\Users\user1/.ssh/id_ed25519' are too open. with no number. The owner must be your own account, and no account other than yours, SYSTEM and the Administrators group may have access. In the file's Properties, open Security, then Advanced: make yourself the owner, disable inheritance, and remove every other user and group.

Messages that look similar

Sources

Spotted a mistake? Email [email protected].