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

How to Fix: SSH key authentication fails with error "Failed publickey for [USERNAME] from [CLIENT IP] port [PORT] ssh2"

SSH key authentication fails with error Failed publickey for [USERNAME] from [CLIENT IP] port [PORT] ssh2. Possible solutions include checking the permissions of authorized_keys and private keys, verifying the host key, and ensuring the correct identity file is used.

Quick Answer: Check the permissions of authorized_keys and private keys, verify the host key, and ensure the correct identity file is used to resolve the issue.

SSH key authentication fails with error "Failed publickey for [USERNAME] from [CLIENT IP] port [PORT] ssh2" affects users trying to establish a secure connection between their local Ubuntu 20.04 machine and a RedHat server using key-based authentication.

This issue is frustrating because it prevents users from taking advantage of the security benefits of key-based authentication, forcing them to rely on password authentication instead.

🛑 Root Causes of the Error

  • The primary reason for this error is that the SSH client on the local machine may not be configured correctly to use the public key. This can occur if the `IdentityFile` option in the SSH configuration file is incorrect or missing, or if the permissions on the private key file are not set correctly.
  • An alternative reason could be that the SSH server on the remote RedHat machine has a restrictive configuration that prevents it from accepting the public key. For example, the server may have a `PubKeyAuthentication` option set to `no`, which disables key-based authentication.

✅ Best Solutions to Fix It

Verify and correct the SSH client configuration

  1. Step 1: Check the `IdentityFile` option in the SSH configuration file to ensure it matches the path to the private key file. For example, `IdentityFile ~/.ssh/id_rsa_[HOSTNAME]_2` should be verified.
  2. Step 2: Verify that the permissions on the private key file are set correctly to allow read and write access for the SSH user. The default permissions are usually `600`, which means only the owner has access.
  3. Step 3: Check the SSH client logs to ensure that it is attempting to use the public key correctly. If the logs show a different `IdentityFile` option, update the configuration file accordingly.

Verify and correct the SSH server configuration

  1. Step 1: Check the `PubKeyAuthentication` option in the `/etc/ssh/sshd_config` file to ensure it is set to `yes`. This option enables key-based authentication.
  2. Step 2: Verify that the SSH server logs show an attempt to accept the public key from the client. If the logs do not show this, check the server's configuration files for any restrictions on key-based authentication.

🎯 Final Words

To resolve the SSH key authentication failure, verify and correct the SSH client and server configurations. Check the `IdentityFile` option in the SSH client configuration file and ensure that the permissions on the private key file are set correctly. On the SSH server side, check the `PubKeyAuthentication` option and ensure that the server logs show an attempt to accept the public key from the client. By following these steps, users should be able to establish a secure connection using key-based authentication.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions