You can edit sudoers
file and set secure_path
to match your path. This is documented in Unix & Linux.
Is there a command line switch I can pass to sudo
such that it uses the path I have set? For example:
rick@alien:~$ sudo echo $PATH
/home/rick/bin:/home/rick/.local/bin:/mnt/e/bin:/mnt/e/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
───────────────────────────────────────────────────────────────────────────────
rick@alien:~$ echo $PATH
/home/rick/bin:/home/rick/.local/bin:/mnt/e/bin:/mnt/e/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
───────────────────────────────────────────────────────────────────────────────
rick@alien:~$ sudo which auto-brightness-config
/usr/local/bin/auto-brightness-config
───────────────────────────────────────────────────────────────────────────────
rick@alien:~$ which auto-brightness-config
/mnt/e/usr/local/bin/auto-brightness-config
───────────────────────────────────────────────────────────────────────────────
rick@alien:~$ sudo locate auto-brightness-config
/Desktop/Link to auto-brightness-config
/home/rick/Pictures/display-auto-brightness-config 1.png
/mnt/e/Desktop/Link to auto-brightness-config
/mnt/e/usr/local/bin/.auto-brightness-config
/mnt/e/usr/local/bin/Link to auto-brightness-config
/mnt/e/usr/local/bin/auto-brightness-config
/usr/local/bin/.auto-brightness-config
/usr/local/bin/Link to auto-brightness-config
/usr/local/bin/auto-brightness-config
When I run using sudo
it is finding the wrong copy of the script in /usr/local/bin
when I really want the version in /mnt/e/usr/local/bin
.
If I don't want to maintain the path in sudoers
file, is there a switch I can pass to sudo
to use my path to find the right command?
echo $PATH
andsudo echo $PATH
are going to give you the same results because Bash expands the variable before running the commands. Instead ofsudo echo $PATH
, usesudo sh -c 'echo $PATH'
. – wjandrea Mar 08 '18 at 02:35sudo /mnt/e/usr/local/bin/auto-brightness-config
– wjandrea Mar 08 '18 at 02:36sudo
to use the user's path. I tried-i
and-h
switches to no avail. Still your point is well-taken. Thanks. – WinEunuuchs2Unix Mar 08 '18 at 02:46sudo $PATH
hierarchical order above, it just doesn't find it with as confirmed bywhich
. I'm the only user on this laptop (I hope no one uses it when I'm working) so every time I set my path I don't want to remember to change it in/etc/sudoers
as well. – WinEunuuchs2Unix Mar 08 '18 at 03:22secure_path
which is default install including useless/snap/bin
and missing important/home/Me/bin
. The default install is:secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"
– WinEunuuchs2Unix Mar 08 '18 at 03:53