GrepBoard/Manuals
605 manuals ·

Fix SSH "UNPROTECTED PRIVATE KEY FILE" (permissions 0644)

·Tested on Ubuntu 24.04 (Docker) · OpenSSH 9.6p1 · 2026-10·Test scope ↓·5 steps

SSH "UNPROTECTED PRIVATE KEY FILE" (0644 too open) means others can read your key, so ssh ignores it. Run chmod 600, or copy the key if you cannot chmod it.

output
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@Permissions 0644 for '/home/bob/.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/bob/.ssh/id_ed25519": bad permissionsalice@127.0.0.1: Permission denied (publickey,password).

Your private key file is readable by the group or by other users, so ssh dropped the key instead of using it. The final Permission denied comes from the client never offering the key, not from the server rejecting it. chmod 600 <key file> fixes it; nothing needs to change on the server.

The FILES section of man ssh says private keys "should be readable by the user but not accessible by others (read/write/execute)", and that "ssh will simply ignore a private key file if it is accessible by others."

[1] Check the path and mode the warning names. The path in Permissions 0644 for '…' is the file to fix.

console
$ stat -c '%a %U:%G %n' ~/.ssh ~/.ssh/id_ed25519 ~/.ssh/id_ed25519.pub700 bob:bob /home/bob/.ssh640 bob:bob /home/bob/.ssh/id_ed25519644 bob:bob /home/bob/.ssh/id_ed25519.pub

Not only 0644: 0640, which only lets the group read, triggers the same warning. Any group or other permission bit trips it. The public key .pub can stay 644.

[2] Close the permissions, and check the directory too.

console
$ chmod 600 ~/.ssh/id_ed25519$ chmod 700 ~/.ssh$ ssh alice@server1 true && echo LOGIN-OKLOGIN-OK

Passing the path with -i gets the same warning and the key is still ignored. ssh-keygen -y -f (to regenerate the public key) also prints the warning and fails.

[3] If the owner is wrong, fix the owner before the mode. The check only applies when the key file is owned by the user running ssh. In testing, a root-owned 644 key used by a normal user with -i logged in without any warning:

console
$ ls -l /srv/key-rw-r--r-- 1 root root 399 Oct 27 01:07 /srv/key$ ssh -i /srv/key -o IdentitiesOnly=yes alice@server1 true && echo LOGIN-OKLOGIN-OK

No warning does not mean safe: every user on that machine can read this key. Give it to the user who uses it and close it to 600.

console
$ sudo chown bob:bob /srv/key && sudo chmod 600 /srv/key

[4] Where chmod does not stick, copy the key. Read-only secret volumes, keys mounted into a container with :ro, and file systems that do not store Unix modes are typical. Copy it under your home with the mode set:

console
$ install -m 600 /srv/key ~/.ssh/deploy_key$ ls -l ~/.ssh/deploy_key-rw------- 1 bob bob 399 Oct 27 01:07 /home/bob/.ssh/deploy_key$ ssh -i ~/.ssh/deploy_key -o IdentitiesOnly=yes alice@server1 true && echo LOGIN-OKLOGIN-OK

A container running as root with a root-owned 644 key mounted does get the warning, unlike step 3, because the owner matches. Copy it to a 600 file there too, or set the file mode to 0400 or 0600 where the key is injected (the secret volume settings, for example).

[5] If Permission denied (publickey) remains after fixing the key, it is a different problem; this time there is no warning, and the answer is in the server log. Continue with the server-side steps in SSH Permission denied (publickey): find the cause. Two similar-looking permission errors:

MessageWhat it is aboutFix
Bad owner or permissions on /home/bob/.ssh/configthe client config file is writable by otherschmod 600 ~/.ssh/config
Authentication refused: bad ownership or modes … (server log)the server's authorized_keys, ~/.ssh, or homeadjust permissions on the server

man ssh says ~/.ssh/config "must have strict permissions: read/write for the user, and not writable by others." With mode 666, ssh does not even start the connection.

Analyze your auth.log (SSH) log in the browser ↗ — nothing is uploaded.

Check it with the ssh_config generator tool ↗ — calculated in your browser.

#ssh#private-key#chmod#permissions