Skip to main content
1 of 4
Tim
  • 106.9k
  • 234
  • 651
  • 1.1k

Do I need to specify the pathname of a command added in `/etc/sudoers`, every time I run it with `sudo`?

For a line that I added to /etc/sudoers, for example:

t ALL=(ALL) NOPASSWD: /path/to/myscript 

/path/to is in PATH of the current user t, but not in PATH of root.

Do I need to specify the pathname of the script every time I run the script with sudo?

$ sudo myscript [sudo] password for t: sudo: changeCpuFreq.sh: command not found 

doesn't work even with password, because myscript's path isn't in PATH of root.

$ sudo -E env "PATH=$PATH" myscript [sudo] password for t: 

works with password, because PATH of t is copied to that of root. But the problem is that it still needs password.

$ sudo /path/to/myscript 

works without password.

Thanks.

Tim
  • 106.9k
  • 234
  • 651
  • 1.1k