Fix SSH Permission denied (publickey) Error
Troubleshoot SSH authentication failures related to keys, permissions, and sshd_config.
Confirmed working on: All Linux Distributions
Before you begin
Problem overview
When attempting to connect to a remote server via SSH, the connection drops immediately with a Permission denied (publickey) message.
Common causes
- Your
.sshdirectory or key files have the wrong permissions on the server. - The public key is missing from the
~/.ssh/authorized_keysfile on the remote server. - The SSH daemon on the server is configured to reject public key authentication.
Solution 1: Fix directory and file permissions
SSH refuses to authenticate if your key files are accessible to other users. You must fix these permissions on the remote server.
- Log into the remote server using an alternative method (like a console or password authentication).
- Set the correct permissions for your home directory:
chmod 755 ~/ - Secure the
.sshdirectory so only you can read, write, and execute it:chmod 700 ~/.ssh - Secure the
authorized_keysfile so only you can read and write to it:chmod 600 ~/.ssh/authorized_keys
If you are troubleshooting from the client side, ensure your private key file (e.g., id_rsa) also has strict 600 permissions.
Solution 2: Verify the authorized_keys file
The server needs to know your public key to authenticate your connection.
- On your local machine, print your public key to the terminal:
cat ~/.ssh/id_rsa.pub - Copy the entire output string.
- On the remote server, open the authorized keys file:
nano ~/.ssh/authorized_keys - Paste your public key on a new line. Make sure it is exactly one continuous line with no unexpected line breaks.
- Save the file and exit the editor.
Solution 3: Enable PubkeyAuthentication in sshd_config
If permissions and keys are correct, the server itself might be rejecting public key logins.
- On the remote server, open the SSH daemon configuration file:
sudo nano /etc/ssh/sshd_config - Locate the
PubkeyAuthenticationdirective. - Ensure it is uncommented and set to
yes:PubkeyAuthentication yes - Save the file and exit the editor.
- Restart the SSH service to apply the changes:
sudo systemctl restart sshd
If you still cannot connect, use ssh -v user@server from your local machine to view detailed debug output and pinpoint the exact point of failure.
Confirm the result
- Repeat the exact action that originally triggered the problem.
- Confirm the original error or symptom is gone and no new warning has appeared.
- If the guide changed a driver, service, package, or system setting, restart once and test again.
- If the result is worse or unexpected, stop. Reverse only the last change using its documented restore option; if none is documented, use your backup or qualified support.
Questions about this fix
Why does SSH care so much about file permissions?
SSH strictly enforces permissions to prevent other users on the system from reading or modifying your private authentication keys.
Can I just use a password instead?
Yes, if the server allows it, but public key authentication is far more secure and protects against brute-force attacks.
Did this fix work for you?
Weighted Consensus Protocol
Did this solution resolve your issue?
Confirming if this works strengthens verification statistics on the registry.
FixingTeam10,000 rep
Official Project Maintainers
The core engineering and moderation team behind FixingBook. We curate, verify, and maintain the standards of the troubleshooting ledger.
Discussion (0)
No comments yet. Share your experience or verify if this fixed your issue!
