How to cancel the currently-applied remaining sudo time-out?

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 cancel 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 just checked that Alt+F2 keeps gksu active for subsequent invocations.

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

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.

Solution 2

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 hello
$ sudo -k
$ jobs
[1]+  Stopped    sudo apt-get install hello
$ fg 1
Loading database...
....

Solution 3

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…

Solution 4

This can’t be done. The parent sudo process will terminate when its child does, and terminating the parent will terminate the children.

Also terminating it externally doesn’t make any sense, as you can’t really know at which point the program will be terminated. The program flow would be unpredictable.

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply