3

I created an instance on Amazon AWS and gave it a key. When it boots I SSH into that instance as ec2-user using that key but I cannot run anything as root. If I type sudo su it asks me for a password.

It's an Amazon Linux 2016.03 instance.

2 Answers2

1

This... is not something that should happen with a default AMI.

To verify, I just spun up an instance using this same image, and I was able to sudo su no problem.

If this is indeed a brand new instance you just spun up, try re-provisioning; if not, then sorry friend, but somehow you managed to lock yourself out; the root account has no password; and the following is the default sudoers config for ec2-user.

ec2-user ALL=(ALL) NOPASSWD:ALL

My connection

[531] ~ > ssh -i ~/.ssh/mclark.pem ec2-user@54.84.179.152
Last login: Mon Apr 11 22:21:37 2016 from c-aaa-bbb-ccc-ddd.hsd1.ma.comcast.net

       __|  __|_  )
       _|  (     /   Amazon Linux AMI
      ___|\___|___|

https://aws.amazon.com/amazon-linux-ami/2016.03-release-notes/
4 package(s) needed for security, out of 6 available
Run "sudo yum update" to apply all updates.
[ec2-user@ip-172-31-54-235 ~]$ sudo su
[root@ip-172-31-54-235 ec2-user]# cat /etc/sudoers.d/cloud-init
ec2-user ALL = NOPASSWD: ALL

# User rules for ec2-user
ec2-user ALL=(ALL) NOPASSWD:ALL
[root@ip-172-31-54-235 ec2-user]#
Matt Clark
  • 685
  • 1
  • 10
  • 26
1

I figured out why it wasn't letting me switch to root. I will post it here for anyone else that may come across a similar issue instead of deleting the question.

I was using Amazon OpsWorks and had specified a user management Chef cookbook which apparently required me to set the sudoers which by default was empty.