SSH access to EC2 Linux Centos

0

Hello I have been able to connect to an instances for many years now all the sudden I can't. It connects and then asks for the root password. Normally, when using the keypair it doesn't prompt.

I have other instances that I can connect to. I'm using mac os native SSH client. I have my pem file chmod 400. I even created a new key pair to see if that would help nothing.

Any ideas?

Thanks in advance.

END3
asked 8 months ago453 views
3 Answers
0

I am sorry to hear you are experiencing this issue. Clearly something has changed from the period when it was working, to this period when it isn't. Generally speaking this could happen due to a corrupted SSH key, issues with the SSH daemon configuration, or file permissions. Because there are some unknowns here, I have included a number of troubleshooting steps that I hope might provide a clue/next step to resolve the issue:

Step 1: Verify the SSH Key Pair Ensure that you are using the correct private key (*.pem file) while initiating the SSH connection.

Step 2: Check SSH Daemon Configuration Access the affected instance through AWS Systems Manager (SSM) or via an EC2 Instance Connect, and check the SSH daemon configuration file (/etc/ssh/sshd_config) to ensure that password authentication is disabled and key-based authentication is enabled. The relevant lines in the configuration file should be:

PasswordAuthentication no
PubkeyAuthentication yes

Step 3: Permissions Ensure that your private key file permissions are set correctly. You've mentioned it's set to 400 which is correct. You can confirm this with the following command:

chmod 400 /path/to/your-key.pem

Step 4: Check Authorized Keys Connect to the instance using an alternative method like SSM and verify that your public key is correctly listed in the ~/.ssh/authorized_keys file of the user you're trying to connect as.

Step 5: Check Server Logs Check the SSH server logs for any indications or details about why the authentication is failing. You can check the logs with the following command:

sudo tail -f /var/log/secure

Step 6: Connection Command Ensure that your SSH connection command is correct. It should be something like:

ssh -i "/path/to/your-key.pem" ec2-user@your-ec2-public-ip

Step 7: Restart SSHD Service After making changes to the SSH daemon configuration file, don't forget to restart the SSHD service to apply the changes:

sudo systemctl restart sshd

Step 8: AWS Documentation If the problem persists, refer to the AWS documentation for troubleshooting SSH (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/TroubleshootInstancesConnecting.html) to investigate the issue in depth.

Step 9: Try Recovering from Backup If you had a specific day when you know this worked, try restoring from that snapshot.

Step 10: Contact AWS Support If you have developer or higher support tier/plan with AWS, considering opening up a chat to help you navigate this question.

I hope this will help lead you to a clue that you can use to resolve the issue. Good Luck!

profile picture
answered 8 months ago
0

asks for the root password

I believe that the default user for a CentOS AMI is centos and not root. Try connecting as that user, and with the original key and not the new one you mention you created, and see if that helps.

profile picture
EXPERT
Steve_M
answered 8 months ago
0

Hi, I got the same issue today. I updated the sshd_config to enable the root user and allow login by password. I used it for months. But today I cannot ssh to the ec2 both with the "root" user (using the password) and the "centos" user (using the original key pairs). Does anyone know how to solve it?

answered 7 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions