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?
Asked
Active
Viewed 2.4k times
3
Akshat
- 387
3 Answers
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
-
@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_timeoutin thesudoersmanual 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
-
-
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
Balvinder
- 51
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
-
-
1@JasonSalaz In my opinoon the hint for setting a timeout is not a full answer, but helpful for the second question "Is there a way to make sudo not ask for a password...?" – Pro Backup Jul 03 '12 at 20:31
sudoersfile. I don't remember the details, butman sudoersandman visudowill help. – ughoavgfhw Jun 06 '12 at 23:41