Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

When using sudo on Linux, it asks for root password, but only the first time you run it. If you run another sudo command, it remember you already entered the password previously and doesn't ask for it:

thomas@ubuntu:~$ sudo id
[sudo] password for thomas: ******
uid=0(root) gid=0(root) groups=0(root)
thomas@ubuntu:~$ sudo id
uid=0(root) gid=0(root) groups=0(root)

How does sudo do it? Where is this information stored? My idea is that it remembers the terminal id (like pts/1), but where is this stored? The first sudo process is ended when it's done with the command, right?

I know sudo is a setuid program, so it has root's privileges all the time, but I still can't think of a good place to store an information that a user has already entered a password. Is there some daemon process involved?

share|improve this question
    
There's a pretty good overview of how sudo works here: aplawrence.com/Basics/sudo.html It details sudo's behavior with remembering passwords (e.g. the default timeout is 5 minutes), although it does not cover the specifics of how sudo remembers the password. Still interesting, though. –  David Apr 24 '12 at 21:07
3  
Just a tiny correction, sudo asks you for your password, not root's password –  Gareth Apr 24 '12 at 22:09
add comment

migrated from stackoverflow.com Apr 25 '12 at 18:47

This question came from our site for professional and enthusiast programmers.

2 Answers

up vote 9 down vote accepted

Where is this information stored?

It's probably under /var/db/sudo or /var/run/sudo and you'll probably find directories of usernames with files under them ordered by tty number.

The actual privileges granted, including how long the sessions lasts before you have to enter your password again depends on how sudoers is setup. There's settings to grant/restrict a lot of different things, but those aren't stored in these files which only store timestamps. How long a session lasts, or when sudo needs to prompt for your password again, is determined by a delta of current time and the session timestamp in this directory, and how long sudo is setup to allow a session to last.

share|improve this answer
    
As to how long, from ubuntu docs: "When using sudo, your password is stored by default for 15 minutes." –  David Englund Apr 24 '12 at 21:20
add comment

Try man sudo and have a look at the FILES section:

/var/lib/sudo Directory containing time stamps

And at the SECURITY NOTES

sudo will check the ownership of its time stamp directory (/var/lib/sudo by default) [...]

(man pages from Debian 6.0.4)

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.