visudo nopasswd does not work for my command

263 Views Asked by At

I have tried most of the solutions to the other available questions, so please do not refer to them. None of them cover my case.

I am on Ubuntu-16.04 and I am trying the following command to run without password prompt:

/usr/local/bin/nanobox run python manage.py runserver 0.0.0.0:8080

I tried different variations, I was able to find - escaping special characters, using wildcards, using command alias and so on:

username ALL=(ALL) NOPASSWD: /usr/local/bin/nanobox run python manage.py runserver 0.0.0.0\:8080
username ALL=(username) NOPASSWD: /usr/local/bin/nanobox run python manage.py runserver 0.0.0.0\:8080
username ALL=NOPASSWD: /usr/local/bin/nanobox run python manage.py runserver 0.0.0.0\:8080
username ALL=(ALL) NOPASSWD: /usr/local/bin/nanobox run python manage.py runserver 0.0.0.0:8080
username ALL=(ALL) NOPASSWD: /usr/local/bin/nanobox run *

Using command alias:

Cmnd_Alias NANOBOX_RUN=/usr/local/bin/nanobox run python manage.py runserver 0.0.0.0\:8080
username ALL=(ALL) NOPASSWD: NANOBOX_RUN
username ALL=NOPASSWD: NANOBOX_RUN
username ALL=(username) NOPASSWD: NANOBOX_RUN

Nothing of this works. I am either getting syntax errors or a password prompt. Please help me with it.

And obviously, I do not want to use

username ALL=(ALL) NOPASSWD: ALL
1

There are 1 best solutions below

0
On

(even though this is very long later..., maybe it helps someone)

After spending many hours yesterday and today searching why for seemingly no reason my sudoers would not allow me to run a command without password for me the solution was painfully easy:

Check your aliases!

I had my shell configured to use an alias like the following

alias sudo='sudo env "PATH=/usr/local/sbin:/usr/local/bin" '

When running the command in plain bash without config it worked perfectly.