chmod Calculator · Tutorial

How to set the right permissions for SSH keys

5 min readbeginnerUpdated

SSH refuses to use a private key that other users can read and stops with “UNPROTECTED PRIVATE KEY FILE”. You will work out the right permissions for the key, the public key and the .ssh folder, and the commands to set them.

What you need

Steps

  1. Start from the key’s current mode

    Keys copied from another machine or a download often end up as 644: readable by everyone. Load the example, which starts at 644 for ~/.ssh/id_ed25519.

  2. Remove access for everyone else

    Apply go-rwx. The mode becomes 600: only you can read and write the key. This is what SSH requires. 400 (read-only, even for you) also works.

  3. Set the folder and public key

    Click Private folder (700) and use the name ~/.ssh to get the folder command. The public key, ending in .pub, may stay at 644 because it is meant to be shared.

    chmod 700 ~/.ssh
    chmod 600 ~/.ssh/id_ed25519
    chmod 644 ~/.ssh/id_ed25519.pub
  4. Check your umask

    With umask 077, new files you create are 600 and folders 700, so keys you generate are private from the start.

Try it yourself

Opens the chmod Calculator with this tutorial's sample loaded.

Try it now

Common mistakes

Fixing the key but not the owner
If the key belongs to another user (for example after copying with sudo), permissions alone won’t help. Run chown $USER ~/.ssh/id_ed25519 first.
Leaving authorized_keys group-writable
On the server, SSH ignores ~/.ssh/authorized_keys if others can write to it or its folders. Use 600 for the file and 700 for ~/.ssh.

Next steps

Go back to the chmod Calculator, or keep going with one of these: