sudo在完全限定的可执行文件之前使用PATH

时间:2022-03-23 23:24:13

I ran into a problem that I've never seen before and can't exactly explain. I was helping someone run a perl based install on a RedHad 4.6 zLinux and running under sudo seemed to grab the system perl rather than the fully qualified perl executable.

我遇到了一个我以前从未见过的问题,无法解释。我正在帮助某人在RedHad 4.6 zLinux上运行基于perl的安装,并且在sudo下运行似乎抓住了系统perl而不是完全限定的perl可执行文件。

Example:

/my/perl/bin> ./perl -v == 5.8.8
/my/perl/bin> /my/perl/bin/perl -v == 5.8.8
/my/perl/bin> sudo /my/perl/bin/perl -v == 5.8.5????

Even though we were fully qualifying the path to our perl it was still grabbing /usr/bin/perl when running under sudo. I have no idea why, any gurus know?

即使我们完全符合我们的perl路径,但在sudo下运行时仍然会抓取/ usr / bin / perl。我不知道为什么,任何大师都知道吗?

3 个解决方案

#1


preserve environment:

sudo -E /my/perl/bin/perl -v

#2


Edit you sudoers config :

编辑你的sudoers配置:

sudo gedit /etc/sudoers

add this line

添加此行

Defaults env_keep +=PATH

this is similar to sudo -Ebut persistent.

这类似于sudo -Ebut persistent。

#3


check if your sudoers file has the the secure_path option set if so then that is your PATH

检查你的sudoers文件是否设置了secure_path选项,如果是,那么那就是你的PATH

Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

#1


preserve environment:

sudo -E /my/perl/bin/perl -v

#2


Edit you sudoers config :

编辑你的sudoers配置:

sudo gedit /etc/sudoers

add this line

添加此行

Defaults env_keep +=PATH

this is similar to sudo -Ebut persistent.

这类似于sudo -Ebut persistent。

#3


check if your sudoers file has the the secure_path option set if so then that is your PATH

检查你的sudoers文件是否设置了secure_path选项,如果是,那么那就是你的PATH

Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"