0

I have read How do I make sudo preserve my environment variables? and I have the lines below in my /etc/sudoers file.

Defaults        env_reset
.....
Defaults        env_keep += "PATH"

but my PATH variable is different when I'm doing sudo as shown below.

ckim@stph45:~/testsocket] printenv PATH
/home/ckim/Neuro/py-faster-rcnn/caffe-fast-rcnn/.build_debug/tools/:/home/ckim/anaconda2/lib:/home/ckim/anaconda2/bin:/home/ckim/uClinux/sparc-uclinux-3.4.4/bin:/opt/abde-rtems/bin:/opt/abde/bin:/opt/abocd/bin:/usr/lib64/qt4/bin:/home1/vivado-2014.3.1/DocNav:/home1/vivado-2014.3.1/Vivado/2014.3.1/bin:.:/bin:/usr/bin:/usr/sbin:/usr/local/bin:/sbin:/usr/X11R6/bin:/usr/local/Acrobat7.0/bin:/home1/cadence/installs/INCISIV152/tools/bin:/home1/cadence/installs/INCISIV152/tools/bin/64bit:/home1/cadence/installs/INCISIV152/tools.lnx86/bin/64bit:/home1/ise132/ISE_DS/ISE/bin/lin64:/home1/ise132/ISE_DS/ISE/synopsys:/home1/ise132/ISE_DS/PlanAhead/bin:/home1/ise132/ISE_DS/ChipScope/bin/lin64:/home/ckim/bin
ckim@stph45:~/testsocket] sudo printenv PATH
/sbin:/bin:/usr/sbin:/usr/bin

What can be wrong? I'm doing it on tcsh on CentOS 6.7 (Final).

EDIT (question changed) : (thanks to quixotic) After adding "." to secure_path in sudoers file, the secure_path is in effect so I can let it find my executable in the current directory, but it gives me this error.

ckim@stph45:~/testsocket] sudo TCPEchoServer 7
sudo: ignoring `TCPEchoServer' found in '.'
Use `sudo ./TCPEchoServer' if this is the `TCPEchoServer' you wish to run

How can I make the shell not ignore "." in secure_path? I don't want to put './executable', that's why I started this question.

  • note the accepted answer on that question and its discussion of sudo's secure_path. also note the full comments below, including another duplicate on serverfault. – quixotic Mar 22 '17 at 8:36
  • ok, I thought having PATH in the env_keep is supposed to do the trick. Anyway, I added "." in the secure_path, becaue I wanted to exeucte a file in current directory where every that may be. After adding "." to the secure_path, it gives me different error. I'll modify my question then. Thanks. – Chan Kim Mar 22 '17 at 8:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.