4

Amazon EC2-instance: I made a user 'admin' and copied ec2-user's keys with proper permission. After successful login, i tried to do sudo su for root access, it says 'admin is not in the sudoers file. This incident will be reported.'

However i can do sudo su with ec2-user account and can gain root access.

What is sudoer file? how does ec2-user and admin different in config wise?

# useradd -m admin
# cp -R /home/ec2-user/.ssh /home/admin
# chown -R admin:admin /home/admin/.ssh

connect by putty: login as: admin Authenticating with public key "xxx" [admin@ip-xx-xx-xx-xx ~]$ sudo su

We trust you have received the usual lecture from the local System Administrator. It usually boils down to these three things: 1) Respect the privacy of others. 2) Think before you type. 3) With great power comes great responsibility.

[sudo] password for admin:
admin is not in the sudoers file.  This incident will be reported.

3 Answers 3

2

You need to edit your sudoers filer and enable your admin user. You should only edit your sudoers file with the visudo command as this checks the syntax etc. Something like

admin    ALL=(ALL) ALL

will do. This allows your admin user to execute any command as on any host as any user after supplying a password.

Check the sudoers and sudo man pages

3

I got a Simple Solution:

  1. login as root user
  2. create a user useradd user1
  3. create a password for a user passwd user1
  4. if you are using amazon ec2 linux add your user to wheel group by usermod -aG wheel user1
  5. then, try to login as your user su user1
  6. use any root command now sudo less /etc/shadow
  7. it Prompt for a password now enter it..
1
  1. Create a new user using 'useradd user1'
  2. Set password for the user 'passwd user1'
  3. Add user to the group wheel 'gpasswd -a user1 wheel'
  4. Logged in as ec2-user open visudo using 'sudo visudo'
  5. Uncomment the line starting with %wheel. i.e. remove the # before %wheel ALL=(ALL) ALL
  6. Logout
  7. Login back as ec2-user
  8. Switch to the user created 'su - user1'
  9. Execute any command with sudo flag to run as root

Worked for me

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .