I updated the OS to 15.5 from 15.4. When executing an app with sudo, the app is not found even though it is in the PATH.
$ sudo echo $PATH
$ sudo fail2ban-client get cgpro-smtp banned
sudo: fail2ban-client: command not found
$ which fail2ban-client
$ sudo which fail2ban-client
which: no fail2ban-client in (/usr/sbin:/usr/bin:/sbin:/bin)
sudo is not using root’s PATH, or the PATH of the current user. Instead it is using a default PATH.
How do I correct this behavior?
Not correcting but avoiding (very personal) advice.
Do not use
su -. It will use
sudo echo $PATH
That does not do what you think it does. It does not show
sudo - it simply shows
$PATH of your user that invokes
You likely want
sudo sh -c 'echo $PATH'
And your second command
quite clearly shows you that
It will use
Oh! You mean like
I forgot to include this:
# root:/home/sma-user3x> cd
# root:/root> echo $PATH
That is not the PATH sudo is using.
You should learn the differences between using “su” and “su -”. Mageia has a nice wiki article for it:
I have no idea, I never use sudo.
I only tell the OP what
sudo - does.
I never use sudo
I understand. Nobody must use
sudo because you do not use `sudo.
That is a complete nonsensical remark.
I said very clear: very personal advice.
You (and others ) may use what they like.
su are two different commands with different defaults (and use different configuration files).
$PATH can be set in a lot of places. You can check default
sudo is using with
sudo sudo -V
and you can change it. See
sudo sudo -V
Is there another step after editing
After changing “
Default env_reset” to “
Default !env_reset”, and adding PATH to “
env_keep”, here is a relevant line from
sudo sudo -V:
Value to override user's $PATH with: /usr/sbin:/usr/bin:/sbin:/bin
Same as it ever was.
I found the magic.
Comment the line for “
Defaults secure_path=” in /etc/sudoers. Or change it to something less restrictive.