A quick example on Ubuntu Linux 22.04 LTS. I had the need for a particular user to have “passwordless” sudo ability. Its not best practice to do this, however if you are restricting the command or commands that a user can run with “passwordless sudo”, you are balancing functionality and security as well as you can.
Adding the line to /etc/sudoers is simple, however you must ensure that it is placed at the end of the file, essentially the configuration that sticks is the last read in the file for that particular user.
You edit the file with “visudo”, don’t try to edit the file directly “visudo” ensures you have correct syntax applied etc.
All you need to do is add the following line to the end of the /etc/sudoers file.
ubuntu ALL=(ALL:ALL) NOPASSWD:ALL
Log out that user and then login again, when running sudo you shouldn’t be prompted for a password.
Another way to achieve this is to add a file to the /etc/sudoers.d/ directory and within that put in the directive above.
For example, create a file called “ubuntu” in /etc/sudoers.d/ and then within it put:
ubuntu ALL=(ALL:ALL) NOPASSWD:ALL
Now, log out and back in again and you’ll find you’ll have password-less sudo. Using a method with a file can be easier to automate with Configuration Management like Ansible.