1

I wrote a Nagios check script which checks if user peeradmin is able to touch a file in some mount on the server.

Nagios user is: nagios .

I've edited /etc/sudoers and added these lines but none worked:

nagios  ALL=NOPASSWD: /bin/su - peeradmin -c /bin/touch
nagios  ALL=(peeradmin) NOPASSWD: /bin/su
nagios  ALL=(peeradmin) NOPASSWD: /bin/su - peeradmin

But still, while logged in as nagios user i'm unable to run any command as user peeradmin without being asked for a password:

[nagios@hadoop-nn1 ~]$ su - peeradmin -c "ls"
Password:

What am I doing wrong and how can I allow user nagios to run commands as user peeradmin?

Thanks in advance,

2 Answers 2

1

Though correct, I think the above answer is a little incomplete.

In order to do both touch and ls as peeradmin user, the rule in /etc/sudoers file should look like:

nagios ALL=(peeradmin) NOPASSWD: /bin/ls, /bin/touch

If you would like to run more commands, then add those commands (with full path) separated with a comma.

Once you do that, just use the following commands as nagios user:

sudo -u peeradmin touch /path/to/the/mount

or

sudo -u peeradmin ls

3

That's because it's sudo config, and you don't run sudo.

sudo su - peeradmin -c "ls" might work.

But really, should should be thinking more in terms of using sudo directly if it's just running commands. e.g.

sudo -u peeradmin ls

For which you'd need an alias:

nagios ALL=(peeradmin) NOPASSWD: /bin/ls

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .