Score:0

Sudoers, Specific Programs & Said programs arguments

de flag

I have a /etc/sudoers.d file which I want to run a program (asterisk) WITH arguments as a user (zabbix). So far I have tried:

zabbix ALL = NOPASSWD: /etc/path/to/my/script.sh

And

zabbix ALL=(ALL) NOPASSWD: /etc/path/to/my/script.sh

which all the script does is run sudo /usr/sbin/asterisk -rx "pjsip show channelstats". I've tried to run this command directly in the sudoers file but even when it then looks like.

zabbix ALL=(ALL) NOPASSWD: /usr/sbin/asterisk -rx "pjsip show channelstats"

And I've also tried escaping the quotes with no luck, which looks like.

zabbix ALL=(ALL) NOPASSWD: /usr/sbin/asterisk -rx \\"pjsip show channelstats\\"

It still asks me for a password. even when I change ALL params to the user 'asterisk' or even 'root' it still asks for a password. When I goto Zabbix (Monitoring Server) and try to retrive said data it get this error message.

sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper

sudo: a password is required

How ever I can get it to work if I just give it the executable, just not with the params which having access to Asterisk without any specific params is a really REALLY bad practise. How can I make it not ask for the password?

P.S I'm always using Visudo for editing the Sudoers file/s.

Thanks.

Marco avatar
br flag
have you tried to escape the quotes in the sudo command: `sudo /usr/sbin/asterisk -rx \"pjsip show channelstats\"` ?
Definity avatar
de flag
@Marco `/etc/sudoers.d/pjsip.show.zabbix:1:56: syntax error zabbix ALL=(asterisk) NOPASSWD: /usr/sbin/asterisk -rx \"pjsip show channelstats\" ^ What now? ` So it seems I can only use the double slash like I've used above in my post.
Marco avatar
br flag
No escape in the config, escape quotes in the command you run.
Definity avatar
de flag
@Marco I did escape the quote with \" and I got the error above. If I use \\" Visudo exits fine and dosen't complain.
Marco avatar
br flag
Again: NO escapes in the sudoer file. Use escapes on the commandline.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.