Allow any arguments for a given command with sudo [closed]
I have the following sudo config entry which I added via sudo visudo
:
mark ALL = NOPASSWD: /usr/bin/lxc-ls*
I can run lxc-ls
with my user fine but I can't append any parameters without it demanding I prefix the command with sudo
.
$ whoami
mark
$ lxc-ls
test-container
$ lxc-ls --fancy
lxc-ls: error: You must be root to access advanced container properties. Try running: sudo /usr/bin/lxc-ls
Any idea how I can edit via sudo visudo
to allow for any argument after the command?
I don't want to prefix the command with sudo as I'm using a python library to execute the command and it's being funny about sudo prefixes.
Update:
I've tried removing the *
but that didn't work either:
$ sudo grep '\-ls' /etc/sudoers
mark ALL = NOPASSWD: /usr/bin/lxc-ls
$ lxc-ls
test-container
$ lxc-ls --fancy
...
lxc-ls: error: You must be root to access advanced container properties. Try running: sudo /usr/bin/lxc-ls
Solution 1:
From the sudoers manual :
A simple file name allows the user to run the command with any arguments he/she wishes
So, drop the *.
You will still need to prefix the lxc-ls command with sudo or write a simple wrapper that does it for you.
Solution 2:
That's not how sudo
works. The sudoers file simply grants the user rights to a command when prefixed by the sudo command, not so you can run it without the sudo being prefixed. You'd need to write a wrapper script (like a simple bash file) to execute the command if your own script can't do it.