Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sudo E option does not work? [closed]

Seems to me that if I write a shell script in $HOME/path/to/script/myscript, and export PATH=$PATH:$HOME/path/to/script/ then sudo -E myscript should run the script right?

From sudo man page:

‑E The ‑E (preserve environment) option indicates to the security policy that the user wishes to preserve their existing environment variables. The security policy may return an error if the ‑E option is specified and the user does not have permission to preserve the environment.

But sudo -E script can't find the command. I know I can just add /absolute/path/to/script/ to the files that determine the PATH variable for sudo env, but that's not the approach I want to take.

To address the comments:
@H2CO3: I have seen sudo sudo floating around the net, and it bugs me tremendously, it's literally saying "Give me superuser permissions to run superuser". I don't know if it would solve the problem, but it seems like a fundamentally flawed approach. Then again I started using linux/bsd systems back in the mid 90's so I take issue with just the sudo command itself.
@rici: The script does have executable permissions, but that's definitely something to check whenever something doesn't run in *nix systems =)

like image 217
MishaP Avatar asked Sep 11 '13 17:09

MishaP


1 Answers

/etc/sudoers by default has a setting to reset the environment. And also defines a default secure_path which is in effect when you run sudo -E [cmd].

You will need to edit the /etc/sudoers file and add 'env_keep' and mention the variables you want to preserve.

Default env_keep += "PATH"

but before this comment out the secure_path line. Then try your command via sudo -E.

like image 117
simp76 Avatar answered Nov 04 '22 01:11

simp76