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
ckim@stph45:~/testsocket] sudo printenv PATH

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.