AWS Opsworks Changes SSH Keys to EC2 Instances

I just had the problem, that I could no longer log in to my EC2 instance with my SSH key:

Server refused our key

I found out, that it was because of, I AWS Opsworks Stacks and had shaken exactly this key for the new stack.

My salvation was, that you can also connect to the instances with SSH via the AWS Console without the certificate:

What Opsworks did then, the key was to be copied from the existing instances and the root user, no longer allocate my ec2-user.

Unfortunately, this was also not done correctly, but the key in /root/.ssh/authorized_keys had been changed to an incorrect format by Opsworks:

command="echo 'Please login as the ec2-user user rather than root user.';echo;sleep 10" xxxxxxxxxxxxxxxxxxxMY SSH Keyxxxxxxxxxxxxxxxxxxx

To restore login, I removed the text in front of my SSH key and copied it to /home/ec2-user/.ssh/.

After that, the appropriate rights have to be set as ec2-user:

mkdir /home/ec2-user/.ssh
sudo chown -R ec2-user:ec2-user /home/ec2-user/.ssh
chmod 700 /home/ec2-user/.ssh
chmod 600 /home/ec2-user/.ssh/authorized_keys

After that, the login was possible again. It should not be forgotten, remove the root SSH Key.

Comments are closed.