Fix PuTTY Server Refused Our Key Error: Best Solution

Posted on

Fix PuTTY Server Refused Our Key Error: Best Solution

Fix PuTTY Server Refused Our Key Error: Best Solution

PuTTY is a widely used, free, and open-source terminal emulator, serial console, and network file transfer application. It supports several network protocols, including SSH, Telnet, rlogin, and SCP. PuTTY is particularly popular for connecting to remote Linux servers from Windows machines. However, users sometimes encounter the frustrating "Server Refused Our Key" error when attempting to authenticate via SSH keys. This article will guide you through troubleshooting and resolving this common issue, ensuring you can securely access your remote servers.

You can now proceed to the guide steps below on the Orcacore website to resolve the Fix PuTTY Server Refused Our Key Error.

Common Causes of PuTTY Key Error

The "Server Refused Our Key" error in PuTTY indicates that the SSH server is rejecting the provided SSH key. This can stem from several issues:

  • Incorrect Public Key: The public key on the server doesn’t match the private key you’re using in PuTTY. This is the most frequent cause.
  • Incorrect Key Permissions: The authorized_keys file or the .ssh directory on the server has incorrect permissions, preventing the SSH server from reading the key.
  • Incorrect Key Format: The public key in authorized_keys might be corrupted or in an incorrect format.
  • Incorrect Username: The private key may be associated with a different username than you’re trying to log in with.
  • Server Configuration: The SSH server (sshd_config) might be configured to disallow key-based authentication or have restrictions on key types.
  • Missing .ssh Directory: The .ssh directory may not exist in the user’s home directory on the server.

The most common culprit is an incorrectly copied public key on your remote server. Let’s walk through the steps to rectify this.

It is a possible error message when you try to connect to the remote SSH server using PuTTY SSH Key: “Server refused our key”.

This happens because you haven’t copied your public key to the remote server or haven’t done it properly. In this guide, we want to show you how to troubleshoot PuTTY Key Error.

1. Open PuTTY Private key File

To resolve the Fix PuTTY Server Refused Our Key Error, you need to open PuTTYgen. Go to File > Load Private key, and open your Private Key File.

PuTTYgen
PuTTYgen

At this point, you will see the Public key in the text box. Highlight it and copy it into your clipboard.

Putty Public key
Public key

2. Edit the authorized_keys file To Fix Server Refused Key Error

Your public key should exist in the authorized_keys file of the user account you used to log in to the remote server.

Log in to the Linux server and change to the home directory with the cd command:

cd ~/

Then, create the .ssh folder and the .ssh/authorized_keys file (if it doesn’t already exist):

# mkdir ~/.ssh
# touch ~/.ssh/authorized_keys

Open the authorized_keys file and paste the public key. Here we use vi editor:

vi ~/.ssh/authorized_keys

Paste your public key in the file. When you are done, save and close the file.

3. Connect to the Remote Server

To connect to the remote server. Open the PuTTY terminal and provide the IP address of the remote server. Then, Go to Connection > SSH > Auth and Load the private key after clicking on the Browse button.

Click on Open to establish an SSH connection to the Linux server. You should be able to connect to the server without getting the “Server refused our key” error.

Alternative Solutions to "Server Refused Our Key" Error

While the above method directly addresses the most common cause of the "Fix PuTTY Server Refused Our Key Error," here are two alternative approaches that tackle other potential underlying issues:

Solution 1: Verifying and Correcting File Permissions

Incorrect permissions on the .ssh directory or the authorized_keys file are a frequent cause of authentication failures. The SSH server is very particular about these permissions for security reasons. The .ssh directory should have permissions of 700 (drwx——), and the authorized_keys file should have permissions of 600 (-rw——-).

Explanation:

  • 700 for .ssh directory: This means the owner (the user) has read, write, and execute permissions. The group and others have no permissions. This is crucial to prevent unauthorized access to your SSH keys.
  • 600 for authorized_keys file: This means the owner has read and write permissions. The group and others have no permissions. This ensures that only the user can modify the list of authorized keys.

Steps:

  1. Log in to your remote server using password authentication (if key authentication is failing).
  2. Navigate to the user’s home directory:

    cd ~
  3. Check the permissions of the .ssh directory and the authorized_keys file:

    ls -ld .ssh
    ls -l .ssh/authorized_keys

    Examine the output. The first line should look like drwx------ for .ssh and the second line like -rw------- for authorized_keys.

  4. If the permissions are incorrect, correct them using the chmod command:

    chmod 700 .ssh
    chmod 600 .ssh/authorized_keys

    These commands change the permissions to the correct values.

  5. Try connecting again using PuTTY and your SSH key.

Why this works: Correcting the permissions ensures that the SSH server can properly read and access the authorized keys for authentication.

Solution 2: Using ssh-copy-id for Key Installation

The ssh-copy-id command is a convenient utility designed to securely copy your public key to a remote server’s authorized_keys file. This method avoids manual copying and pasting, reducing the risk of errors.

Explanation:

ssh-copy-id automates the process of adding your public key to the remote server’s authorized_keys file. It first attempts to connect to the server using your existing credentials (usually password authentication). Once connected, it appends your public key to the authorized_keys file. This is a safer and more reliable approach than manually copying the key.

Steps:

  1. Ensure you have the ssh-copy-id command available on your local machine. It’s typically included in most Linux distributions and can be installed on macOS using Homebrew: brew install ssh-copy-id. Windows users can use it within WSL (Windows Subsystem for Linux).
  2. Open your terminal or WSL terminal.
  3. Use the ssh-copy-id command to copy your public key to the remote server. Replace user@remote_host with your actual username and hostname or IP address:

    ssh-copy-id user@remote_host

    You will be prompted for your password on the remote server.

  4. ssh-copy-id automatically appends the key to ~/.ssh/authorized_keys, creating the directory and file if needed.
  5. Try connecting again using PuTTY and your SSH key.

Why this works: ssh-copy-id simplifies the key installation process, ensuring the key is correctly placed and formatted in the authorized_keys file. It also handles creating the necessary .ssh directory if it doesn’t exist.

Example (using WSL):

Let’s say your username on the remote server is ubuntu and the IP address of the server is 192.168.1.10. In your WSL terminal, you would run:

ssh-copy-id ubuntu@192.168.1.10

You’ll be prompted for the password for the ubuntu user on 192.168.1.10. After entering the password, ssh-copy-id will copy your public key to the server.

Conclusion

The “Fix PuTTY Server Refused Our Key Error” error can be frustrating, but it is usually caused by a simple misconfiguration. By carefully following the steps outlined above, including verifying key content, checking file permissions, or utilizing ssh-copy-id, you should be able to resolve the issue and establish a secure SSH connection to your remote server. Remember to double-check your work and consider the alternative solutions if the initial fix doesn’t resolve the problem. Now you have learned to troubleshoot, fix, or resolve Fix PuTTY Server Refused Our Key Error Putty SSH Key Error.

Hope you enjoy it. Please subscribe to us on Facebook, Twitter, and YouTube.

You may also like these articles:

Fix phpMyAdmin SSL Error Connection

Clear DNS Cache in Linux

Fix “apt-add-repository” Command Not Found on Debian 11

Resolve APT Error pkgproblemresolver Held Broken Packages

SMTP Can Not Find Mail Address in Ubuntu

CSF Error Path to iptables Not Set or Incorrect

Leave a Reply

Your email address will not be published. Required fields are marked *