Bash – Added bin directory to the path, can’t execute commands in it with ‘sudo command’

bashrcpathroot

I made a bin directory in my home folder where I place all my scripts. Then in my .bashrc I added the following:

export PATH=$PATH:/home/myusername/bin

So I could access files I placed in there from anywhere. But some of the scripts need to be executed as root. So I thought, I could symlink my .bashrc as root, (as in /root/.bashrc points to /home/myusername/.bashrc, don't know if this is smart) so when I need to run a script as root I can just do:

sudo program_that_requires_root

But then I get a:

sudo: program_that_requires_root: command not found

If I login as root and execute the program, it works fine though. So what is the correct way to accomplish what I want?

Best Answer

You have to make sure these two lines are present in the sudoers file.

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

See these URLs for more details:

Related Question