I am using AWS Linux AMI2, I added ec2-user ALL=(ALL) ALL and saved the file.

Now when I run any command with sudo it displays [sudo] password for ec2-user:

How to reset this file?

  • 1
    Does this help, over on ServerFault - serverfault.com/q/144988/267016
    – roaima
    Jun 29 '19 at 10:45
  • 1
    Can you boot with some other OS image and mount the drive/volume from your VM? Been a long time since I played with EC2, but Linode, DigitalOcean, etc provide for this with their vms....
    – ivanivan
    Jun 29 '19 at 15:07

Just remove that line.

If the problem is that you don't know the password for ec2-user, then you must find some other way to get root access.

The line ec2-user ALL=(ALL) ALL means that sudo will ask for a password, because you didn't specify NOPASSWD.

  • True, but the question is how do I do this, if sudo is not working? Jul 8 '19 at 8:48
  • @ctrl-alt-delor If you are locked out, you are locked out, nothing you can do. Otherwise, find a way to get access. Boot a rescue system, mount the image to another instance, or download the disk image, modify and upload.
    – RalfFriedl
    Jul 11 '19 at 17:40
  • @Yes than is the type of answer they are looking for. How to get un-locked out. Jul 11 '19 at 18:58

By default, sudo requires that a user authenticate him or herself before running a command.

This behavior can be modified via the NOPASSWD tag.

For a single user, try


We can also modify the syntax to allow specific commands like

USERNAME ALL= NOPASSWD: /bin/kill, /bin/ls

Suoders manual has more details covering this topic

  • All very true, but how does this answer the question? Jul 8 '19 at 8:46
  • use the pkexec visudo to make the changes Jul 8 '19 at 9:36

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.