Software⏱️ 4 min read📅 2026-06-11

How to Fix: Error 'Permission denied (publickey,password)'

SSH connection error due to permission denied. Find solutions for OpenSSH and SSH key management.

Quick Answer: Check SSH key permissions, ensure the correct identity file is used, and try re-generating the SSH key pair.

The 'Permission denied (publickey,password)' error occurs when your local machine is unable to connect to a remote server using SSH. This error affects users who are trying to access a server via SSH from their terminal.

This issue can be frustrating, especially if you're familiar with the process and have successfully connected in the past. In this guide, we'll walk through the steps to troubleshoot and resolve this common problem.

⚠️ Common Causes

  • The primary reason for this error is that your local machine's SSH client is unable to authenticate with the remote server using either public key or password authentication. This could be due to several reasons such as incorrect configuration, missing private keys, or incompatible versions of OpenSSH on both machines.
  • An alternative cause could be a firewall blocking the connection or issues with the remote server's SSH daemon.

✅ Best Solutions to Fix It

Configuring SSH Client and Server for Public Key Authentication

  1. Step 1: Step 1: Verify that you have a valid private key file (.pem or .key) in your local machine's ~/.ssh directory. Ensure that the private key is not encrypted and has the correct permissions (755).
  2. Step 2: Step 2: Check the SSH client configuration to ensure it's set to use public key authentication. Open your terminal and run 'ssh -v user@192.168.0.2' to verify the connection options.
  3. Step 3: Step 3: Generate a new private key file if you haven't already done so. Run 'ssh-keygen -t rsa -b 2048' (or choose another suitable key type) and follow the prompts to save the key in your local machine's ~/.ssh directory.
  4. Step 4: Step 4: Copy the public key from the remote server to your local machine using 'scp user@remote_server:.ssh/id_rsa.pub'.
  5. Step 5: Step 5: Add a new rule to your local machine's SSH client configuration file (usually located at ~/.ssh/config) with the following content: Host 192.168.0.2 User user IdentityFile ~/.ssh/id_rsa
  6. Step 6: Step 6: Restart your terminal or run 'source ~/.bashrc' (or your shell's equivalent command) to apply the changes.
  7. Step 7: Step 7: Test the connection again using 'ssh -v user@192.168.0.2'.
  8. Step 8: method_2_name

Alternative Advanced Fix

  1. Step 1: Step 1: Check your remote server's SSH version and configuration for compatibility with your local machine's OpenSSH client.
  2. Step 2: Step 2: Verify that the remote server's firewall is not blocking the connection. You can use 'ufw status' or 'iptables -n -L' to check the current rules.
  3. Step 3: Step 3: Ensure that the remote server has a valid SSH public key and private key pair. If not, generate new keys using 'ssh-keygen -t rsa -b 2048'.
  4. Step 4: Step 4: Check the remote server's SSH daemon configuration to ensure it's set to allow password authentication. This may require editing the sshd_config file.
  5. Step 5: Step 5: Restart the remote server's SSH service after making any changes.
  6. Step 6: method_2_name

💡 Conclusion

If you've followed these steps and are still experiencing issues, try troubleshooting further by checking your local machine's and remote server's event logs for any error messages. If none of the above solutions work, consider seeking assistance from a system administrator or IT professional for more in-depth guidance.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions