Wednesday, September 23, 2009

Extending sudo credentials

If you use sudo for, e.g. pkgsrc's just-in-time su, you may have often bitten by the problem that some compilations are slow and the build process stops right in the middle to ask you for a root password. If you go away while the system compiles, you'll be frustrated when you come back, as the process may still well be at the very beginning.

This happens because, unless disabled by the system administrator, your sudo credentials last for 5 minutes. If you hadn't used sudo for those 5 minutes, it will ask you for your password again. A simple workaround for the problem is to automatically renew your credentials, say, every 2 minutes. You can do this by running the following command (from the same console you are using later on!) right before starting a pkgsrc build:
$ ( while :; do sudo -v; sleep 120; done ) &

2 comments:

mirabilos said...

Excuse me, but you, as a BSD developer,
please can’t tell me you didn’t RTFM
for about three minutes – sudoers(5) –
to discover the timestamp_timeout op-
tion, right? Please say it isn’t.

Your workaround is really more of a
würgaround and certainly doesn’t help
in getting sudo accepted more widely.

Just sudo visudo, then add lines like
this ↓ then save and exit. This will
give you unlimited timeouts. (Note: on
e.g. Kunterbuntu systems you’ll also
need to disable tty tickets.)

Defaults passwd_timeout=0
Defaults timestamp_timeout=-1

Julio Merino said...

Looks like I didn't make it clear. Yes, the system administrator can change the default, but I don't want to.

You certainly don't want to raise the timeout to many hours (covering the longest possible compilation that you'll do), as doing that is almost like not setting any timeout at all. So running the command I shown is only a temporary measure for a specific situation without having to change the defaults.