You set up key-based login, try to connect, and SSH answers with Permission denied (publickey). This ssh permission denied error means the server refused every key you offered — but it rarely tells you why. The cause is almost always one of a handful of configuration or permission problems. This guide walks through the diagnosis in the order that finds the fault fastest. This article covers How to Fix SSH Permission Denied in detail.
What the SSH Permission Denied (Publickey) Error Means – How to Fix SSH Permission Denied
With publickey authentication, your client offers keys to the server, and the server checks them against the authorized_keys file in your home directory. If none match — or the server is not allowed to read the file — the login is refused. A correct diagnosis starts on the client side with verbose output.

Step 1: Run SSH in Verbose Mode – How to Fix SSH Permission Denied
The -v flag shows exactly which keys are offered and rejected:
ssh -v -i ~/.ssh/id_ed25519 user@your-server
Look for lines such as Offering public key: ... followed by Server accepts key or silence. If your key is never offered, the client is not loading it — check the file name or specify it explicitly with -i. If it is offered but rejected, the problem lives on the server side. If you have not created a key pair yet, follow our guide on how to generate SSH keys on Linux first.
Step 2: Confirm the Public Key Is Installed Correctly
On the server (log in with a password or console access if you still can), verify that your public key — the .pub file — exists on a single line in the right place:
cat ~/.ssh/authorized_keys
Common mistakes: pasting the private key instead, line breaks introduced by copy-paste, or adding the key to the wrong user’s file (for example root’s file while logging in as another user). The safest way to install a key is ssh-copy-id user@your-server from your own machine.
Step 3: Fix Ownership and File Permissions
This is the number-one cause of ssh permission denied errors. SSH ignores keys if permissions are too open, because StrictModes treats loose permissions as a security risk:
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
chown -R $USER:$USER ~/.ssh
chmod 755 ~
The home directory itself must not be group- or world-writable either. After fixing permissions, try connecting again — in practice, this step alone solves most cases.
Step 4: Check the sshd Configuration
If permissions are right, inspect the server configuration for restrictions:
sudo sshd -T | grep -Ei "pubkeyauthentication|authorizedkeysfile|allowusers|passwordauthentication"
Make sure PubkeyAuthentication is yes, and that your username is not excluded by AllowUsers/DenyUsers in /etc/ssh/sshd_config (remember that files in /etc/ssh/sshd_config.d/ can override it — cloud images often drop a file there that disables settings). After any change, validate and reload:
sudo sshd -t
sudo systemctl reload ssh # Ubuntu/Debian
sudo systemctl reload sshd # RHEL/AlmaLinux
Step 5: Read the Server-Side Auth Log
The server logs the exact rejection reason:
sudo tail -f /var/log/auth.log # Ubuntu/Debian
sudo journalctl -u sshd -f # RHEL family / systemd
Messages like Authentication refused: bad ownership or modes for directory confirm the permission problem from Step 3, while Failed publickey for user with no further detail points back to a key mismatch. If you also changed the SSH port for security, make sure you are connecting to the right one — see our note on how to change the SSH port on Linux.
How to Prevent SSH Permission Denied Problems
Always keep one working session (or console access) open while changing SSH settings, test new keys in a second terminal before logging out, and document which keys are installed where. The official sshd manual page documents every configuration option mentioned in this guide.
A Note on Agent and Key Passphrases
Two client-side traps deserve a mention because verbose output makes them look like server rejections. If your key has a passphrase and no agent is running, some clients silently skip the key instead of prompting — start the agent and load the key explicitly with eval "$(ssh-agent -s)" and ssh-add ~/.ssh/id_ed25519, then reconnect. Similarly, servers cap how many keys a client may offer (controlled by MaxAuthTries, default six); if your ~/.ssh/config or agent holds many keys, the right one may never be reached. In that case connect with ssh -o IdentitiesOnly=yes -i ~/.ssh/id_ed25519 user@server so only the specified key is offered. Both problems vanish once the key file itself is correct, which is why Step 1’s verbose output — it lists every offered key in order — is worth reading carefully before changing anything on the server.
Conclusion
An ssh permission denied (publickey) error comes down to four suspects: the key was never offered, the wrong key is installed, permissions are too open, or sshd is configured to refuse you. Verbose mode on the client and the auth log on the server will pinpoint which one — and the fix is usually a two-minute job.