3

Why does sudo ask for a password when one can sudo su without a password and perform the same commands? Is there a way to make sudo not ask for a password when you're logged in as the an admin anyway?

Akshat
  • 387
  • You can remove the password by modifying your sudoers file. I don't remember the details, but man sudoers and man visudo will help. – ughoavgfhw Jun 06 '12 at 23:41

3 Answers3

6

sudo su asks for a password on my system. Did you run another sudo command before the sudo su? Once you've run sudo and entered your password, it doesn't require a password again for a period of time.

Cajunluke
  • 17,704
  • 1
    Where "a period of time" is 5 minutes IIRC. – Jason Salaz Jun 07 '12 at 01:30
  • @JasonSalaz That sounds about right. I didn't want to look it up, and the exact time didn't seem all that relevant. – Cajunluke Jun 07 '12 at 01:57
  • @JasonSalaz: Yes, by default. See the entry timestamp_timeout in the sudoers manual page. – Harald Hanche-Olsen Jun 07 '12 at 11:38
  • I tried opening a new terminal window before I posted the question but it appears sudoing the password goes across windows – Akshat Jun 07 '12 at 12:30
  • Indeed, it's system-wide. – Daniel Jun 07 '12 at 15:30
  • Just for completeness' sake, it's system-wide until some recent version of sudo. Some time in the last few months, my Linux system's sudo behavior changes, and the 5 minute sudo timeout is PER SHELL. Meaning if I run a command via sudo, open a new tab and run another command via sudo, I have to re-auth on the second tab, but can go back to the first one and keep using sudo within the timeout. Just don't be surprised if/when it makes it's way to OS X :). – Jason Salaz Jun 07 '12 at 18:37
  • @JasonSalaz That makes a lot of sense. I'm surprised that didn't make it in until now. – Cajunluke Jun 07 '12 at 18:43
5

You can just modify following lines in /etc/sudoers :

# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL

# Allow members of group sudo to execute any command
%sudo  ALL=(ALL:ALL) ALL

to

# Members of the admin group may gain root privileges
%admin ALL=(ALL) NOPASSWD: ALL

# Allow members of group sudo to execute any command
%sudo  ALL=(ALL:ALL) NOPASSWD: ALL
Jason Salaz
  • 24,471
0

sudo will always want a password once, but just set a crazy long timeout -- and note that it is specified in minutes:

Defaults env_reset,timestamp_timeout=60

Will E.
  • 109
  • 1