linux - Shell script getting superuser privilege without being run as sudo -
here script:
script.sh:
sudo cat /etc/passwd- if in sudo session (e.g ran other command sudo few minutes ago), , run
script.sh the script sudo access. if run cat /etc/passwd-/, permission denied error.
as user, wouldn't expect script.sh able super user privileges (e.g without me giving access superuser privileges sudo script.sh).
is expected behavior ? configurable ?
i see behavior being similar sudo su, e,g potentially giving superuser access script run in session, worse, because might not aware of it, , don't know when ends (at least not without checking manually)
is expected behaviour ?
yes, indeed expected behavior. user's cached credentials sudo responsible it.
is configurable ?
yes configurable.
and think security concern valid one. running script.sh in terminal sudo command run before (within timeout), give script superuser privilege if script written explicit sudo commands.
you can avoid script not prompting password when run sudo running with:
sudo -k script.sh it ask password regardless of previous sudo command/s or session.
and run script.sh without sudo i.e
script.sh, still prompt password sudo command/s:
you can change timeout value (the duration sudo maintains session) permanently:
run sudo visudo
then change line:
defaults env_reset to
defaults env_reset,timestamp_timeout=0 save , exit (ctrl+x y)
this ensure sudo asks password every time run.
or if don't want change permanently , want script prompt password @ least once (while maintaining session), can change script this:
sudo -k first-command-with-sudo sudo second-command sudo third , on this script prompt password @ least once regardless of previous sudo command/s or session.
in case unaware of (or don't have access to) content of script script.sh (it can have sudo commands inside or not)
and want sure sudo command surely prompt password @ least once, run sudo -k (capital k) before running script.
now if run script.sh , if contains sudo command, surely prompt password.
Comments
Post a Comment