Does the ssh command specify the key pair as below?
ssh -i ./key.pem centos@ec2-IP-Address
Also, if the public key permissions are not appropriate, SSH may not be possible with the key pair.
Lists the public keys (DSA, ECDSA, Ed25519, RSA) that can be used for logging in as this user. The format of this file is described above. The content of the file is not highly sensitive, but the recommended permissions are read/write for the user, and not accessible by others.
If this file, the ~/.ssh directory, or the user's home directory are writable by other users, then the file could be modified or replaced by unauthorized users. In this case, sshd will not allow it to be used unless the StrictModes option has been set to “no”.
Key-based authentication is tried initially, and if that fails then it goes on to ask for a password.
In addition to @Riku_Kobayashi's advice to ensure the private key is readable by you and nobody else, also make sure you are on the latest version of your SSH client, as some older versions use (what are now considered to be) insecure key-exchange algorithms which a newer OS like CentOS 8 may not trust.
And according to the CentOS website the correct username on CentOS 8 is centos https://www.centos.org/download/aws-images/
- Accepted Answerasked 3 months ago
- asked 2 years ago
- Where can I find SSH login credentials so that I can connect to my Lightsail instance from an SSH client?AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated a year ago
- Why am I getting a "Server refused our key" error when I try to connect to my EC2 instance using SSH?AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 9 months ago
- EXPERTpublished 4 months ago