The "unsupported authentication methods available" error in Putty occurs when the SSH server rejects key-based login because the public key is missing, misplaced, or has incorrect file permissions on the EC2 instance. This typically happens after manually modifying user profiles or migrating keys without following AWS-specific initialization steps. Resolving it requires verifying the ~/.ssh/authorized_keys file exists, contains the correct public key, and has strict ownership and permission settings.
Understanding the Authentication Failure
When you attempt to connect via SSH, the client (Putty) sends a list of supported authentication methods, such as public-key authentication. The server responds by listing the methods it supports for that specific user account. If the server sees no valid method that matches what the client offered, or if the required files are inaccessible, it returns an empty list of acceptable methods, leading to the "unsupported" error. This is distinct from a "Permission denied" error, which usually means the key was found but rejected due to bad format or wrong owner. Here, the server essentially says, "I have nothing I can use to authenticate you." This often points to structural issues within the home directory rather than just a wrong password or key mismatch. For users transitioning from other cloud providers or setting up custom AMIs, these directory structures are critical. You might also encounter related connectivity hurdles, such as those detailed in our guide on Troubleshooting kex_exchange_identification Error in Linux SSH Connection, which helps isolate network-level issues before diving into file permissions.Verifying File Permissions and Ownership
The most common cause is incorrect permissions on the hidden.ssh directory and the authorized_keys file. Linux SSH daemons are extremely strict about security; if a directory or file is writable by group or others, the server will ignore them entirely to prevent spoofing.
First, access your instance using the AWS Systems Manager Session Manager or by creating a new temporary instance and mounting the root volume if direct SSH is completely blocked. Once inside, check the permissions for the user you are trying to log in as (e.g., ec2-user, ubuntu, or centos).
Run the following commands to correct the permissions:
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
chown -R $USER:$USER ~/.ssh
The .ssh directory must be accessible only by the owner (700). The authorized_keys file must be readable and writable only by the owner (600). Any deviation, such as 644 or 755, will cause the SSH daemon to silently reject the key. Ensure that the ownership matches the username exactly. Using chown with $USER ensures you do not accidentally assign root ownership, which would also break authentication.
Checking the Authorized Keys Content
Even with perfect permissions, the file may be empty or contain malformed data. Open theauthorized_keys file using a text editor like nano or vim:
nano ~/.ssh/authorized_keys
Verify that the line starts with ssh-rsa, ssh-ed25519, or another valid key type, followed by the base64-encoded key string, and ends with the comment identifier (usually your email or hostname). Common errors include:
- Line Wrapping: If the key was copied from a terminal or PDF, it might have wrapped to the next line. The entire key must be on a single line.
- Extra Characters: Ensure there are no invisible characters, spaces at the beginning of the line, or trailing whitespace that could invalidate the key.
- Missing Key: The file might be completely empty. If you recently reset permissions, you might have overwritten the file instead of editing it.
Inspecting SELinux and AppArmor Contexts
In some distributions, particularly RHEL, CentOS, and Amazon Linux 2, SELinux (Security-Enhanced Linux) enforces strict contexts on files. If theauthorized_keys file does not have the correct SELinux context, the SSH daemon cannot read it, even if Unix permissions are correct.
Check the current context with:
ls -Z ~/.ssh/authorized_keys
The output should show a context similar to ssh_home_t. If it shows user_home_t or something else, you need to restore the default context. Run:
restorecon -Rv ~/.ssh
This command resets the SELinux labels to their default values based on the directory structure. For Ubuntu instances, AppArmor is less likely to block this specific file unless custom profiles are active, but checking logs in /var/log/auth.log can provide clues if SELinux is not the culprit.
Reviewing SSH Daemon Configuration
If permissions and keys are correct, the SSH server configuration itself might be restricting authentication methods. Edit thesshd_config file, usually located at /etc/ssh/sshd_config. Look for the line:
PubkeyAuthentication yes
Ensure this is set to yes and not commented out. Also, check the AuthorizedKeysFile directive. It should point to .ssh/authorized_keys. If it has been changed to a custom path, ensure your key is in that location. After making changes, restart the SSH service:
sudo systemctl restart sshd
On some older systems, the service might be named ssh instead of sshd. Always verify the service name with systemctl list-units --type=service | grep ssh.
Frequently Asked Questions
Why did this happen after a reboot?
This rarely happens spontaneously after a clean reboot unless a script modified permissions during startup. More commonly, it appears after an instance stop/start cycle if the root volume was detached and reattached incorrectly, causing ownership to shift to root. Always verify ownership after any volume manipulation.
Can I use password authentication instead?
You can enable password authentication by setting PasswordAuthentication yes in sshd_config, but this is strongly discouraged for security reasons. Password logins are vulnerable to brute-force attacks. It is better to fix the key-based authentication issue than to weaken your server's security posture.
What if I don't have console access?
If SSH is completely locked out, use the AWS Console to stop the instance, detach the root EBS volume, and attach it to a helper instance. Mount the volume, fix the permissions and keys, unmount, and reattach it to the original instance. This is a standard recovery procedure for broken SSH configurations.
Does Putty handle RSA keys differently?
Putty uses its own format (.ppk) for private keys. However, the server-side authorized_keys file still requires the standard OpenSSH public key format. You must convert your Putty private key to an OpenSSH public key using PuTTYgen before adding it to the server, or generate a new key pair in OpenSSH format.
How do I check the SSH logs for more details?
View the system logs using journalctl -u sshd or check /var/log/secure (RHEL/CentOS) or /var/log/auth.log (Ubuntu/Debian). Look for lines mentioning "authentication refused" or "bad ownership" to pinpoint whether the issue is permissions, SELinux, or key format.