This article is a brief overview of what Sudo nopasswd is and how to run commands on Linux as a sudo user without having to enter your password every time. Sudo (superuser do) command in Linux lets a user run a command as the root by entering your password . However, if you are the only person using the system and require to run commands as the root user, again and again, entering the password every time could get a bit tedious.
In this tutorial we will see how we can run commands as the root user without having to type in the password. A word of caution, be careful who you grant this power to cause as they say, with power comes responsibility.
The way to do this is really simple. You just have to make an addition to the /etc/sudoers file. The /etc/sudoers file controls who can run what commands as what users and can also control special things such as whether you need a password for particular commands.
1. Open /etc/sudoers for editing
First, we need to edit the suoders file. You can manually edit the file by entering the path /etc/sudoers or edit it with the visudo command which will automatically open the file in your default command-line editor as root. In my case, the default is set to nano editor:
$ sudo visudo
This will open a screen that looks like:
2. Modify the file
To grant the permission to run commands as root users without the need of entering the password, add the following line at the end.
<username> ALL=(ALL) NOPASSWD:ALL
After making the change, exit and save the changes. To exit press Cntrl +X. Then press ‘Y” to save the changes.
3. Take it for a test run!
Let’s see if our little change gave our user the password-free root access. I gave the sudo nopasswd access to a user named Jayant. To test it out first switch to the user and try running a command with sudo.
It runs without asking for password.
Conclusion
That’s it for this tutorial. This little hack can come in handy and save you from the redundant act of entering the password each time you run a command as the root user. Make sure that you take a backup of the /etc/sudoers file if necessary before making changes to it.