3

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
3
  • 3
    This looks perfectly normal to me, perhaps you should read the information provided more carefully, they're sure to contain information that is pertinent to your current issue. – user9517 Nov 11 '13 at 7:07
  • 2
    Agree. This is definitely not off-topic and shows an understanding of the problem (as shown by the fact that people were able to respond). If the OP's misunderstood the sudo syntax fine, but there's no reason to close the bloody topic. – Dave Feb 10 '15 at 17:16
  • 1
    BTW - I put a space between the * and the command, and that seems to have sorted it for me. See also this question on superuser But you do have to run with sudo for it to work of course :) – Dave Feb 10 '15 at 17:29
9

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.

3
  • No joy, I've edited my question showing the output. – Mark L Nov 11 '13 at 7:08
  • 5
    Reading is fundamental. – dmourati Nov 11 '13 at 7:12
  • 2
    The sudoers manual is long, complex, and not well organized. There is no example to cover this common use case. The quoted sentence is in the middle of a paragraph. It's extremely reasonable to miss it. – Reid Jun 3 '19 at 22:12
5

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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.