17

On a sandbox VM environment, I have a setup of Ubuntu Linux which is firewalled and cannot be accessed from outside the local system. Therefore, on that VM, I'd like to give the administrative user (which I set up) the ability to run anything with sudo and not need a password.

While I know this is not secure, this VM is not on all the time, and requires my personal passcode to run. So even though this is not "secure", is there a way to get the desired functionality?

2 Answers 2

23

From man sudoers:

   NOPASSWD and PASSWD

   By default, sudo requires that a user authenticate him or herself
   before running a command.  This behavior can be modified via the
   NOPASSWD tag.  Like a Runas_Spec, the NOPASSWD tag sets a default for
   the commands that follow it in the Cmnd_Spec_List.  Conversely, the
   PASSWD tag can be used to reverse things.  For example:

    ray  rushmore = NOPASSWD: /bin/kill, /bin/ls, /usr/bin/lprm

   would allow the user ray to run /bin/kill, /bin/ls, and /usr/bin/lprm
   as root on the machine rushmore without authenticating himself.

One other tag is ALL, to allow the user ray to run any command on any host without password you can use:

ray ALL= NOPASSWD: ALL
2
  • 2
    The configuration file this answer is describing is /etc/sudoers. You do not edit this like a normal configuration file, instead you should use the visudo command (as root).
    – paulhauner
    Commented Nov 29, 2017 at 22:29
  • you answer works but if I want to limit it to /bin/su - david by adding ray ALL= NOPASSWD: /bin/su - david, it still asks for password when I run, /bin/su - david. Any idea? Thanks!
    – HCSF
    Commented Jun 1, 2022 at 15:12
1

As you mentioned it is a bad idea to disable the password prompt unless the system runs in a particular secure environment.

One possible solution is this one-liner that I find easier to remember than the NOPASSWD option. Get administrative privileges and run

$ visudo

and add the following line

Defaults: username !authenticate

This will disable the password prompt entirely for a particular user.

You must log in to answer this question.

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