I want to allow one user to run grep (through sudo), and to grep for one specific string in one specific file. I don't want to allow this user to be able to run grep on all files. The user doesn't have read access to the file, hence the requirement to use sudo. I am trying to write a nagios check which greps the log file of another service on the machine.
However it doesn't work, sudo keeps asking for a password.
My command is: sudo grep "string I want (" /var/log/thefilename.log
(yes, there is a raw (
and some spaces in the string I want to grep)
/etc/sudoers.d/user-can-grep
has this content:
user ALL=(root) NOPASSWD: /bin/grep "string I want (" /var/log/thefilename.log
This sudoers file is owned by root:root
and has permissions -r--r-----
The server is Ubuntu trusty 14.04.3 LTS.
How can I make this work?
sudo
. – user253751 Apr 26 '16 at 22:22grep
, andwhich grep
tells me it's using/bin/grep
. AFAIK in sudo file you need to specify the full path of the binary, even if you call it without the full path. – Amandasaurus Apr 27 '16 at 08:16