LinuxMid

SSH key rejected: Permission denied (publickey) with correct keys

sshd silently refuses keys when the home directory or .ssh files are too open. Read the server log and fix the owner and modes that StrictModes checks.

What you see

  • Permission denied (publickey). although the public key is in authorized_keys
  • It worked before and nothing about the key changed

What it means

By default sshd checks the modes and ownership of the user's home directory and key files before it accepts a login. If they are writable by others, sshd refuses the key. The client only sees a generic denial.

The real reason is written in the server's log, so read that instead of guessing from the client side.

How to confirm the cause

  1. 1
    Read the server log for the rejected login
    sudo journalctl -u ssh -b | tail -30

    The unit is ssh on Debian and Ubuntu and sshd on RHEL and derivatives. Look for lines about bad ownership or modes.

  2. 2
    Check ownership and modes on the home directory and key files
    ls -ld ~ ~/.ssh ~/.ssh/authorized_keys

    Expected: the user owns all three. authorized_keys is 600, ~/.ssh is 700, and the home directory is not writable by group or others.

  3. 3
    Confirm StrictModes is on
    sudo sshd -T | grep -i strictmodes

    StrictModes is on by default and is the check that causes this.

Causes and fixes

  • Home directory or .ssh is writable by others

    HOW TO TELL
    ls -ld shows group or world write bits, or the wrong owner.
    ROOT CAUSE
    sshd treats a file that someone else could edit as untrustworthy, because that person could add their own key. It refuses rather than risk it.
    FIX
    Fix the modes and the owner.
    chmod 700 ~ ~/.ssh
    chmod 600 ~/.ssh/authorized_keys
    sudo chown -R USER:USER ~/.ssh
  • Wrong user or key file on the client

    HOW TO TELL
    The server log shows no key was offered, or a different user.
    ROOT CAUSE
    The client is offering a different key, or connecting as a different account than the one that holds the key.
    FIX
    Run ssh -vvv and check which key file and user are used. Match them to the account on the server.

How to stop it coming back

  • Create ~/.ssh with mkdir -m 700 and the file with umask 077.
  • Use configuration management to set these modes, so a manual change does not undo them.
  • Keep a console or session-manager path to the server in case SSH breaks.

Keep going

Sources

Linux man-pages (man7.org) and the systemd manual (freedesktop.org), read 18 Nov 2026. Command options were checked against those pages.

Search

Search cheat sheets and projects