1

I have a strange issue where sudo is not preserving the PATH by default. I tried the answers from this question and it works when I use the sudo env "PATH=$PATH" version but I want to fix this permanently.

Here's my PATH as regular user and under sudo:

$ echo $PATH
/usr/local/bin:/bin:/usr/bin:/opt/jdk/bin:/opt/python3/bin:/opt/qt5/bin
$ sudo printenv | grep 'PATH'
PATH=/bin:/usr/ucb:/usr/bin:/usr/sbin:/sbin:/usr/etc:/etc

I tried sudo -E and sudo "PATH=$PATH but they don't work either. sudo env "PATH=$PATH" works but I have to type it every time run sudo. I want to avoid doing that every time I run sudo.

I'm not sure where sudo is picking up this path from. I don't have secure_path hard-coded or env_reset in /etc/sudoers. Hence this is not a duplicate of this question.

Any ideas what is going on and how to fix this? I would prefer not create aliases or hard-code the secure_path.

Edit:

As requested, the output of sudo -l:

$ sudo -l
User munir may run the following commands on munir-lfs:
    (ALL) NOPASSWD: ALL
  • 1
    What does sudo -l report? – muru Nov 4 '16 at 4:06
  • @muru Added that to the question – Munir Nov 4 '16 at 13:07
  • @ThomasDickey I have already seen that question and it is linked in the first paragraph of my question but it is not a permanent solution. Like I have already mentioned in the question, I want this to be fixed without having to do sudo env "PATH=$PATH. Basically I want the PATH under sudo to be the same as the users PATH, always. – Munir Nov 4 '16 at 14:06
  • There's more than one solution offered there, some are permanent. – Thomas Dickey Nov 4 '16 at 14:11
  • @ThomasDickey I tried all...none of them worked. I wouldn't be asking this question otherwise. I don't want to hard-code the secure_path unless as a last resort. – Munir Nov 4 '16 at 14:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.