Skip to content
FixingBook
Verifiedbeginnerest. 10 minutes

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

Match the environmentUse this guide only for All Linux Distributions or a clearly compatible setup.
Protect recoveryBack up important data and save encryption or account recovery keys before changing system state.
Know when to stopMake one change at a time and stop if the result differs from what the guide describes.

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 .ssh directory or key files have the wrong permissions on the server.
  • The public key is missing from the ~/.ssh/authorized_keys file 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.

  1. Log into the remote server using an alternative method (like a console or password authentication).
  2. Set the correct permissions for your home directory:
    chmod 755 ~/
  3. Secure the .ssh directory so only you can read, write, and execute it:
    chmod 700 ~/.ssh
  4. Secure the authorized_keys file so only you can read and write to it:
    chmod 600 ~/.ssh/authorized_keys
Expert Tip

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.

  1. On your local machine, print your public key to the terminal:
    cat ~/.ssh/id_rsa.pub
  2. Copy the entire output string.
  3. On the remote server, open the authorized keys file:
    nano ~/.ssh/authorized_keys
  4. Paste your public key on a new line. Make sure it is exactly one continuous line with no unexpected line breaks.
  5. 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.

  1. On the remote server, open the SSH daemon configuration file:
    sudo nano /etc/ssh/sshd_config
  2. Locate the PubkeyAuthentication directive.
  3. Ensure it is uncommented and set to yes:
    PubkeyAuthentication yes
  4. Save the file and exit the editor.
  5. Restart the SSH service to apply the changes:
    sudo systemctl restart sshd
Caution

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

  1. Repeat the exact action that originally triggered the problem.
  2. Confirm the original error or symptom is gone and no new warning has appeared.
  3. If the guide changed a driver, service, package, or system setting, restart once and test again.
  4. 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

Consensus0%
Required100% (Weight 3)
Contributors0
Verified By YouNo
Your Weight--

Did this solution resolve your issue?

Confirming if this works strengthens verification statistics on the registry.

Sign In to VerifySign in required to verify

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.

Spotted something outdated? Suggest an edit. Maintainers review submissions within 48 hours.
Share:XReddit

Discussion (0)

No comments yet. Share your experience or verify if this fixed your issue!

Join the Discussion