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 inauthorized_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
- 1Read the server log for the rejected login
sudo journalctl -u ssh -b | tail -30
The unit is
sshon Debian and Ubuntu andsshdon RHEL and derivatives. Look for lines about bad ownership or modes. - 2Check ownership and modes on the home directory and key files
ls -ld ~ ~/.ssh ~/.ssh/authorized_keys
Expected: the user owns all three.
authorized_keysis600,~/.sshis700, and the home directory is not writable by group or others. - 3Confirm StrictModes is on
sudo sshd -T | grep -i strictmodes
StrictModesis 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 -ldshows 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 -vvvand check which key file and user are used. Match them to the account on the server.
How to stop it coming back
- Create
~/.sshwithmkdir -m 700and the file withumask 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
- Runbook: EC2 SSH: Permission denied (publickey) and unprotected key file
- Runbook: A systemd service failed to start
- Cheat sheet: SSH
- Cheat sheet: Linux Permissions
- Lesson: the linux topic in Learn
Sources
Linux man-pages (man7.org) and the systemd manual (freedesktop.org), read 18 Nov 2026. Command options were checked against those pages.