Excellent software and practical tutorials
How to solve "The selected user key is not registered on the remote host"
In useXshellRemote loginAWSWhen you use the server, you will encounter "The selected user key is not registered on the remote host" Basically every novice will encounter the same error, so what exactly causes the error "The selected user key is not registered on the remote host" during SSH connection? The following is a detailed analysis of the causes of the error.
The Xshell tool is one of the more popular SSH remote tools. Compared with putty, it is more powerful and supports openssh.
In the creationEC2After you connect to the server, you will encounter an SSH security warning when connecting using SSH.
Please verify the host key.
The host key of xxx is inconsistent with the one stored in the local host key database. The host key has been changed or someone is trying to eavesdrop on this connection. If you are unsure, it is recommended to cancel this connection.
I am a little confused at this point. Is it a problem with the key generated by AWS or a problem with the SSH connection using Xshell? Next, I will troubleshoot the problem step by step.
Step 1: First check if the username is wrong. AWS has a small pitfall, that is, the default username for each type of server is different.Google CloudThat is the default root. Let's take a look at the various AWSLinuxThe username for the instance.
What is the default username for Amazon EC2 Linux instances (for SSH, PuTTY, etc.)
Linux instances on EC2/AWS servers (Ubuntu, Debian, Fedora, Amazon Default username for Linux, etc.
- Amazon Linux 2023/Amazon Linux 2/Amazon Linux ec2-user
- CentOS centos or ec2-user
- Debian admin
- Fedora fedora or ec2-user
- RHEL ec2-user or root
- SUSE ec2-user or root
- Ubuntu ubuntu
- Oracle ec2-user
- Bitnami bitnami
The default user name of the RHEL system installed on the test machine is ec2-user or root. When connecting remotely, I tried both user names but still could not connect.
AWS official help page:https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/connect-to-linux-instance.html
Step 2: After confirming that the problem is not with the username, check whether there is a problem with the key.
Instructions for remote connection using keys are given in the official documentation.
You must know the location of the private key file to connect to your instance. For SSH connections, you must set permissions so that only you can read the file.
For information about how key pairs work when using Amazon EC2, see Amazon EC2 Key Pairs and Linux Instances.
Find the private key
Get the fully qualified path to the location on your computer of the .pem file for the key pair that you specified when you launched the instance. For more information, see Identifying the public key specified at launch. If you can't find the private key file, see I lost my private key. How do I connect to my Linux instance?
If you use Putty to connect to the instance and need to convert the .pem file to .ppk, see theConverting a Private Key Using PuTTYgen in the Connecting to a Linux Instance from Windows Using PuTTY topic.
Set permissions on your private key so that only you can read it
from macOS or Linux connection
If you plan to use an SSH client on a macOS or Linux computer to connect to your Linux instance, use the following command to set permissions on the private key file so that only you can read it.
chmod 400 key-pair-name.pem
If you do not set these permissions, you cannot connect to your instance using this key pair. For more information, see Error: Private key file is not protected.Connecting from Windows
Open File Explorer and right-click the .pem file. Select Properties > Security tab and select Advanced. Select Disable inheritance. Remove access permissions for all users except the current user.
Try to modify the properties of the private key when connecting remotely in Windows.
After modifying the properties, the key still cannot be used to connect.
Step 3: Check whether the version of the SSH remote connection tool Xshell 6 is too low, resulting in the inability to perform SSH connection.
Because I had been using Xshell 6 to manage the server on my computer, I hadn't updated Xshell for a long time. So I updated Xshell 6 to Xshell 7 and tried to connect again.
Connection successful!
After a lot of trouble, it turned out that the problem was that the Xshell version was too low.
Finally, to sum up, remote connectionAWS EC2If you cannot connect to the server, the most likely reason is that you did not enter the correct username, such as the default input root
Another reason is that the SSH software version is too low. Upgrade Xshell.
If you don't have a freeAmazon CloudFor server AWS EC2, you can register for free.
Apply for 12 months of free AWS Amazon cloud server Amazon cloud Amazon cloud latest tutorial
AWS China official website: https://aws.amazon.com/cn/
Amazon Web Services official website: https://www.amazonaws.cn/