Claire Williams
Claire Williams

Reputation: 41

Amazon EC2 AMI Root Authorized_keys

I'm working with the public RedHat AMI on EC2, and am trying to create an image that by default allows ssh for root. I changed the /etc/ssh/sshd_config file so that PermitRootLogin is set to yes, and changed /root/.ssh/authorized_keys so that the file starts with ssh-rsa instead of:

no-port-forwarding,no-agent-forwarding,no-X11-forwarding,command="echo 'Please login as the user \"ec2-user\" rather than the user \"root\".';echo;sleep 10". 

After I do this, I am able to ssh into my instance as root, but when I create a custom AMI from this instance, the /root/.ssh/authorized_keys file reverts back to the old version that disallows it.

I was wondering how to make it so that my custom AMI has root ssh enabled by default, or if there's a file somewhere that is changing root's authorized_key file back to the original that I can edit.

Thanks!

Upvotes: 4

Views: 2354

Answers (1)

Jon W
Jon W

Reputation: 15806

I've seen similar things happen with Ubuntu/Debian AMIs.

The most likely culprit is cloud-init.

In our case, adjusting disable_root: true => disable_root: false in /etc/cloud/cloud.cfg did the trick.

Upvotes: 3

Related Questions