0

we all know that in Ubuntu sudo password will be auto saved for 15 minutes and expires after that. But I want to make it for quick expire. I mean I dont want to change any settings and when I ever I want , My system should have to release the password with out storing for 15 min. I mean it should store only 3 min or 4 min for example.

how can i do that ?

Raja G
  • 102,391
  • 106
  • 255
  • 328

5 Answers5

2

Edit your sudoers file with sudo visudo and add the following line after the existing defaults:

Defaults    timestamp_timeout=3

Note: visudo doesn't mean it'll neccessarily edit it with vi/vim/etc but if you find your $EDITOR value is sqwiffed-up and you'd prefer nano, you can run sudo EDITOR=nano visudo instead to force nano to be your editor.

The trick from the suggested duplicate, (sudo -k) is good for an immediate privilege dump.

Oli
  • 293,335
  • Boss I want to have temp expire , like "" sudo apt-get install & Remember password only for 2 min and then expire "" – Raja G Oct 01 '13 at 13:29
  • I don't think there's a way to do that on a when-you-like basis. You can either apply the timestamp_timeout to everybody, specific users/commands inside, both in sudoers or manually with the sudo -k command. – Oli Oct 01 '13 at 13:32
1

You can cancel the remaining sudo timetout with

sudo -k 

As explained here

But if you want to change the default from 15 minutes you can do so by

sudo visudo

This opens an editor and points it to the sudoers file -- Ubuntu defaults to nano, other systems use Vi. You're now a super user editing one of the most important files on your system. No stress!

(Vi specific instructions noted with (vi!). Ignore these if you're using nano)

Use the arrow keys to move to the end of the Defaults line.

(vi!) press the A (capital "a") key to move at the end of the current line and enter editing mode (append after the last character on the line).

Now type

,timestamp_timeout=X

where X is the timeout expiration in minutes. If you specify 0 you will always be asked the password. If you specify a negative value, the timeout will never expire. E.g.

Defaults env_reset,timestamp_timeout=5

(vi!) hit Escape to return to command mode. Now, if you're happy with your editing, type in :w to write the file and :q to exit vi. If you made a mistake, perhaps the easiest way is to redo from start, to exit without saving (hit Escape to enter the command mode) and then type :q! .

hit CTRL + X, then Y, then to save your file and exit nano.

You might want to read the sudoers and vi manual pages for additional information.

man sudoers

man vi

Most of this lifted directly from RootSudoTimeout in The official Ubuntu documentation

Warren Hill
  • 22,112
  • 28
  • 68
  • 88
1

I think I have found that , use at command.

i mean

sudo apt-get install <application> & echo "sudo -k" | at now + 2 min 
Raja G
  • 102,391
  • 106
  • 255
  • 328
1

Or you can concatenate the sudo -k

sudo apt-get install package ; sudo -k

The method could be anything that allows you to remove sudo permissions at the end.

Braiam
  • 67,791
  • 32
  • 179
  • 269
0

You could use something like the following bash function (I have not tested this well):

function tmpsudo {
    sudo ${*:2}
    (sleep $(($1 * 60)) && sudo -k) &
}

You would use it like so for a 2 minute timeout:

tmpsudo 2 command

It's really messy and there's no timer-reset, but it's an option.

Oli
  • 293,335