Command running as root but not with sudo
I'm currently configuring a Samba 4 DC on CentOS 7.
As myself, samba-tool
runs fine but when I run sudo samba-tool
I get command not found
.
samba-tool
is located in /usr/local/samba/bin
. I've added the directory to the PATH for both myself and root.
As myself, env | ^PATH=
correctly includes the above directory. However, sudo env | ^PATH=
shows only PATH=/sbin:/bin:/usr/sbin:/usr/bin
.
Switching now to the root user. env | ^PATH=
returns PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/samba/bin:/usr/local/samba/sbin
and samba-tool
runs just fine.
It was my intuition that sudo perfectly mirrored the root user, which I guess is not the case. A fix and hopefully an explanation is highly appreciated.
Solution 1:
It may be your sudo
uses PATH
defined in /etc/sudoers
file, not the root's PATH
. Check man 5 sudoers
, look for the secure_path
option.
You may also read
How to make sudo
preserve $PATH?
Hint: use visudo
to edit /etc/sudoers
. The tool does some sanity check and may save you from the situation when you lose sudo access due to invalid edit.