PDA

View Full Version : [SOLVED] BASH Command To Deactivate Elevated Privileges?



dniMretsaM
October 5th, 2011, 06:56 PM
I'm writing a Python script that will be running some BASH commands with elevated privileges. However, since when you run a command with sudo it keeps the elevated privileges for a period of time, I want to require the password again even if the user entered it before they run the script (just to help keep people from doing something accidentally). What command do I need to run to force this time to end and require the password again?

Arndt
October 5th, 2011, 06:59 PM
I'm writing a Python script that will be running some BASH commands with elevated privileges. However, since when you run a command with sudo it keeps the elevated privileges for a period of time, I want to require the password again even if the user entered it before they run the script (just to help keep people from doing something accidentally). What command do I need to run to force this time to end and require the password again?

See the man page for 'sudo'.

karlson
October 5th, 2011, 06:59 PM
I'm writing a Python script that will be running some BASH commands with elevated privileges. However, since when you run a command with sudo it keeps the elevated privileges for a period of time, I want to require the password again even if the user entered it before they run the script (just to help keep people from doing something accidentally). What command do I need to run to force this time to end and require the password again?

Do you need to run everything with elevated privileges or just some portions?

dniMretsaM
October 5th, 2011, 07:08 PM
See the man page for 'sudo'.

Ok thanks, found that sudo -v resets the time stamp. It says in the man page that it doesn't run a command. Does this mean I need to run sudo -v and then run sudo command and not just sudo -v command?


Do you need to run everything with elevated privileges or just some portions?

Just certain parts (although most of it will require elevated privileges).

Lars Noodén
October 5th, 2011, 07:09 PM
Try sudo -k (http://manpages.ubuntu.com/manpages/oneiric/en/man8/sudo.8.html) or sudo -K. That will cancel the escalated privileges. When you run sudo again it will ask for the password after that.

dniMretsaM
October 5th, 2011, 07:13 PM
Try sudo -k (http://manpages.ubuntu.com/manpages/oneiric/en/man8/sudo.8.html) or sudo -K. That will cancel the escalated privileges. When you run sudo again it will ask for the password after that.

Ok, that'll work. Big thanks.

ajgreeny
October 5th, 2011, 08:52 PM
Alternatively if you want the sudo elevated permissions to always disappear after the command has been run, independent of your script, and for all users, you can set the timeout to zero by editing the /etc/sudoers file. Do this only with the command
sudo visudo and then look for the line
Defaults env_reset and add to it so it looks like
Defaults env_reset, timestamp_timeout=0