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.

When I've just run sudo, and don't want it to remain active for the normal duration of its time-out, how can I cancel that remaining active time-out?

sudo -k kills it for the current terminal session, but if a process is currently running in that session and so can't run sudo -k, is there a way to cancel it from another terminal session?

And is there a way to disalbe all currently applied sudo times (for all terminal sessions, and all gksudo running apps.. etc? ... Although, come to think of it. a running GUI may simply need to be shut down, but I think Alt+F2 caries a memory of the gksu.... (just checked it.. yes, Alt+F2 does keep the gksu active for subsequent invocations)

share|improve this question

3 Answers 3

up vote 13 down vote accepted

Not sure if you mean to kill a sudo timeout so it doesn't timeout or so it times out immediate, but if you want to remove the remaining timestamp you can use sudo -k

Otherwise,if you're trying to cancel a timeout so sudo doesn't timeout, I don't think that is possible to do in a current session. The only way I know of would be to change the timestamp_timeout in the sudoers file and restart the session.

share|improve this answer
    
oops.. I was a bit slow with the detail: I just added a bit more to my question.. about "-k" ...and, yes, I am referring to a one-off situation, although it does now bring up the issue of a system-wide "one-off". ... Thanks (+1) for the asnwer which was perfect for my oringinaL (lacking detail) question.. –  Peter.O Nov 26 '10 at 3:55
    
I don't quite understand how -K is practically different to -k (when -k is used by itseld).., but -k has a double useage: 1. by itself (invalidates the timestamp)... 2. when used with a command, it prompts for a password, regardless of whether or not a previous sudo timeout has expired..... And by the way: sudo -k works in Alt+F2 to kill the timestamp of a previous sudo/gksu call. –  Peter.O Nov 26 '10 at 7:43
    
Yeah I have no idea when I would use one over the other. –  wajiw Nov 26 '10 at 7:49
    
Aside from the "kill all existing timestamps" issue.... Without changing the underlying sudoers settings, the only way I can see to run a "guaranteed` one-time-only sudo is sudo -k; sudo -k appname .... because although sudo -k appname forces the user to enter the password, it leaves a pre-existing timestamp unchanged... (I mention it just as "griss to the mill")... and maybe the simplest way to "kill" all existing timestamps, is to simply avoid the issue entirely and press Ctrl+Alt+L to Lock the screen. :) –  Peter.O Nov 26 '10 at 8:14
    
hahaha if you have the ability, I would go with that option –  wajiw Nov 26 '10 at 8:19

Just on one of your points:

but if a process is currently running in that session and so can't run sudo -k

This is specific to the command line, if you want to do anything while some other process is running, you can press Ctrl+Z to pause the process; you then get access to the current terminal again, do anything you like. When you're done, you can type jobs to get a list of processes, with a number beside them. Type fg 1 (for example - and simply fg if there's only one job) to restart a process, raising it to the foreground. Similarly, bg to do the same thing but leaving the process running in the background.

Example session

$ sudo apt-get install hello
<CTRL+Z>
[1]+  Stopped    sudo apt-get install hallo
$ sudo -k
$ jobs
[1]+  Stopped    sudo apt-get install hallo
$ fg 1
Loading database...
....
share|improve this answer
1  
Stefano: Thanks... that is so good... Linux keeps saying to me, "Yes, off course I can do it" :) ... and, come to think of it, I was half-aware of that Ctrl+Z, but half isn't quite enough!)... Now that I've enountered a "real" situation where it isn't just text on the screen, I'm sure I'll never forget it... must go.. I've got some Cntrl+Z-ing to do... –  Peter.O Nov 26 '10 at 11:02

I found a solution. since my search didn't show anything alike and this is a frequent question: sudo stores somewhere on the filesystem (for example in /var/run/sudo), one directory per user-name, several files that work as the time-stamp, one file for each terminal. delete those files and your system is secure again. just keep in mind that those files are only visible to root (otherwise an intruder might read the time-stamp and set clock-time back to a point where they still were valid -- granting root-ls to anyone is dangerous). therefore in my /etc/pm/sleep/ and maybe also for the screensaver I run:

rm -f /var/db/sudo/*/*

as root of course...

share|improve this answer

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.