Ubuntu – using a sudo command without a password for a certain app

scriptssudo

I'm using a python script to run docker, but docker requires sudo commands to run and it's bad practice to store the sudo password in the file or give the whole python script sudo rights, I've seen a method where you enable the system to run certain commands without entering a password, I've tried it but
I can't get my head around it, I mainly entered it wrongly (I think) I even corrupted my sudoers file once and fixed it.

So can anyone explain this line for me and why it's not working?

username ALL = (root) NOPASSWD: /usr/bin/docker

Best Answer

To prevent corrupting the /etc/sudoers file, always use the visudo command. If you don't like the default editor set the EDITOR environment variable to your desired one.

Put your user specification line as the last line in the sudoers file.

Update:

Please see: Adding NOPASSWD in /etc/sudoers doesn't work