Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I execute quite a lot of sudo commands.

I noticed that if I execute one and then another one within few minutes, the 2nd time I don't get the message:

[sudo] password for my_username:

but I do get it when there is more time between the execution of the two commands.

What's the period of time in which the message is not appearing? How can we check it / update it?

share|improve this question
1  
sudo visudo, then %sudo line should be %sudo ALL=(ALL:ALL)NOPASSWD: ALL , it will not ask you any password when you type sudo any-stuff –  Qasim Jun 17 '13 at 11:41
2  
This (NOPASSWD:ALL) is a very dangerous suggestion. It will make your installation unsecured. –  Sri Jun 19 '13 at 5:24

3 Answers 3

up vote 20 down vote accepted

The default timeout of sudo is 15 minutes; that is, sudo will remember your password for 15 minutes by default.

You can modify this default timeout by adding a string in the file /etc/sudoers. However, you don't modify the file directly, but instead you use the command sudo visudo.

So, type sudo visudo in a terminal. This will open up the (actually, a temporary) file for us to edit, using your preferred editor.

Note: if you are using visudo for the first time, you should be asked which editor you would like to use, so choose your editor. There's no "better" editor, but I prefer nano. If you've already used visudo and chose an editor before, but you want to use another editor for the time being, you can do sudo EDITOR=vi visudo to use vi, or change it to nano to use nano. If you want to permanently change your preferred editor, do sudo update-alternatives --config editor.

Look for this line:

Defaults    env_reset

And add timestamp_timeout=X (with a comma) at the end of it, where X is the time you want to set in minutes.

So your line should look like this, as an example:

Defaults    env_reset,timestamp_timeout=5

If you specify 0, you will always be asked the password. If you specify a negative value, the timeout will never expire.

Once done, save and exit.

Source: RootSudoTimeout

share|improve this answer
    
Thank you, @Alaa, it is a good and helpful answer. Just as a side note, the Ctrl + x part is not always matched as the editor can be for example vi (in my case). –  fedorqui Jun 17 '13 at 13:42
    
By the way, I did a big mistake adding a new line with only Default timestamp-0 instead of the one with env_reset. It broke my sudoers file. Had to use askubuntu.com/a/73872/143251 to solve it! –  fedorqui Jun 17 '13 at 13:45
    
@fedorqui: That is exactly why you should use visudo (as Alaa recommends) instead of editing the file directly. The former will syntax check the file for you, preventing you from locking yourself out of sudo. –  Plutor Jun 17 '13 at 14:20
    
Yes, yes, that's what I did @Plutor . But vi is the editor I have defined for visudo. The problem is that I saved the file although I got a warning message when closing it. My fault, obviously. –  fedorqui Jun 17 '13 at 14:25
1  
@fedorqui, yeah I sort of wanted to remove that part because anyone could be using a different editor. I've edited my answer to not be editor specific. –  Alaa Ali Jun 17 '13 at 17:24

See this post here: http://ubuntuforums.org/showthread.php?p=116697#post116697

Edit /etc/sudoers file, use sudo visudo command for safety. Add timestamp_timeout=0 to the line starting Defaults to ask everytime, or positive X for X minute delay.

share|improve this answer
1  
I have to register in the forum to see it. In the meanwhile, could you kindly indicate which file should I edit with timestamp_timeout=0 line? –  fedorqui Jun 17 '13 at 11:31
    
OK, fixed answer. –  Tuminoid Jun 17 '13 at 11:37
    
It did the trick! I will accept the other answer as it has a more comprehensive explanation and includes the env_reset reference, which is important. Anyway this your answer was also very helpful, so thanks! –  fedorqui Jun 17 '13 at 13:47

Not sure if this expires or not, but you could try

sudo su

It will ask you for the password and after that all commands are run as sudo.

share|improve this answer
    
Yes, @Rat2000, but I want to keep using my user and not root. I think it is safer. Anyway, thanks for the advice. –  fedorqui Jun 17 '13 at 13:46
2  
sudo su makes you become root. Your prompt should then be root@yourpc. Mind that root has it's own .bashrc, so your aliases won't work. Mind also that root can do severe damage to the system, so be careful! –  speter Jun 17 '13 at 17:00

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.