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.

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

  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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.