Views:
1,203β
Votes: 4β
β
Solution
Tags:
command-line
sudo
paths
Link:
π See Original Question on Ask Ubuntu β§ π
URL:
https://askubuntu.com/q/1012922
Title:
Can I make `sudo` follow my path via CLI?
ID:
/2018/03/08/Can-I-make-_sudo_-follow-my-path-via-CLI_
Created:
March 8, 2018
Upload:
September 15, 2024
Layout: post
TOC:
false
Navigation: false
Copy to clipboard: false
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?