Are you a Linux or Unix operating system user? Then yes, sudo is your extensive helper command in Linux. On the Linux operating system, you can run commands as another user using the sudo command. Sudo is the most commonly used tool in the Linux system. But before running commands, sudo needs user authentication.
Users need to log in using their user ID and password before using the command. But entering the password every time might become hectic. This article will discuss the sudo command, how to use the sudo command, and set up the sudo no password for commands in the next sections.
Using a root account, you must be done with the initial setup before running the commands. You can access the root by using the $sudo command. But you must know the password initially.
Setup Sudo No Password for Specific Command Only
Following are some step-by-step commands that will help you know how to use the sudo command without a password to execute all commands.
Where user_list is a list of users already created, Host_list is a list of hosts where the users can run sudo.
Effective_user list is a list of the users who might be running as an alias. Tag_list is tags such as NOPASSWD. In the command list, we pass the commands we don’t want to write the passwords to.
As a root user, you need to write the # visudo or $ sudo visudo command.
In the second step, you need to append the entry of the following given command without password for the specified user (say user vidya):
Then save and close the file and test the result by typing [[email protected]]$sudo /bin/kill pid-here command.
So in the given ways, we can set up the sudo no password command.
Now, if you want to setup sudo no password for specific command only, then here is the step-by-step method:
Let’s take an example where we will use mkdir in sudo without providing a password. So here is the simple way of using mkdir to create a directory:
Note: DATAFILE in the above command is the folder we have created.
Now we will open the visudo panel through the following command:
After that, scroll down to the bottom, where /etc/sudoers.d is present, and then put the below command in it:
We have used morbius ALL=NOPASSWD:/bin/mkdir as we need to provide sudo privileges to mkdir without using a password.
Finally, we will verify that system is successfully accepted the command, so we created one more folder using mkdir, and this system didn’t ask about the password:
If you want to use two different commands with no password, you can use the below command in the visudo panel:
Here we are setting up no password for apt commands. That’s why we have used the /usr/bin/apt command.
Now here is the result:
This article has discussed the sudo command, how to use the sudo command, and the sudo no password for all or specific commands. We also have seen the syntax of the sudo command for no password. We hope you enjoyed the article. Please visit our website to read more articles.