Skip to main content

Timeline for How to make `sudo` preserve $PATH?

Current License: CC BY-SA 4.0

12 events
when toggle format what by license comment
May 18, 2018 at 18:38 comment added mikeTronix I just create an alias called psudo for these types of cases, where: alias psudo="sudo env \"PATH=$PATH\"". Then my normal sudo use is unaffected.
May 9, 2018 at 12:50 history edited Stéphane Chazelas CC BY-SA 4.0
added 1 character in body
Apr 15, 2018 at 13:43 comment added Stéphane Chazelas @ballsatballsdotballs. As that alias should only affect your interactive shells, that should be relatively harmless.
Apr 15, 2018 at 13:42 comment added Stéphane Chazelas @EliahKagan and Hakan, you're right, I've edited the answer.
Apr 15, 2018 at 13:41 history edited Stéphane Chazelas CC BY-SA 3.0
added 224 characters in body
Apr 13, 2018 at 11:32 comment added Eliah Kagan @StéphaneChazelas Does sudo "PATH=$PATH" godi_console ever really work? sudo accepts VAR=value arguments, affecting the environment of the command it runs, but unlike in env or bash, sudo doesn't seem to let this affect how it looks up the command. I only tested this (recently) on Ubuntu 16.04. But I tried adding the exempt_group option to sudoers (just for testing--I don't consider this a solution!) and the results were illuminating. Commands of the form PATH="$PATH" sudo some-command started working, but those of the form sudo PATH="$PATH" some-command still did not.
Apr 12, 2018 at 16:22 comment added derricw Is it okay to use sudo env "PATH=$PATH" as an alias for sudo? What kind of problems could this create?
Jan 25, 2018 at 6:29 comment added Hakan Baba sudo "PATH=$PATH" godi_console did not work in CentOs7 by the way. Needed the env
Feb 15, 2016 at 9:31 history edited Stéphane Chazelas CC BY-SA 3.0
added 173 characters in body
Mar 11, 2015 at 0:31 comment added Alois Mahdal I like this answer best since it avoids need to change settings globally (i.e. preserves principle of least privilege)
Jul 16, 2013 at 20:55 vote accept hugomg
Jul 16, 2013 at 9:12 history answered Stéphane Chazelas CC BY-SA 3.0