How Can I Sudo Another User Without A Password?
In Linux platforms, a sudo user is a tool that implies “superuser do” to run various systems’ commands. A sudo user is typically a root user or any other user who has some privileges. To delegate important tasks like server rebooting or restarting the Apache server, or even to create a backup using the sudo command, you can use the sudo without having to enter the password again and again.
By default, sudo user needs to provide some user authentication. At times, user requirements are to run a command with these root privileges, but they do not desire to type a password multiple times, especially while scripting. This is easily doable in Linux systems. In this article, we will check the method to sudo another user without entering their password.
Running sudo command without a password
To back up your sudo users, you need to copy the /etc/sudoers file from one place to another. Use the following command to do so:
$ sudo cp /etc/sudoers /root/sudoers.bak
Now, to edit the /etc/sudoers file, we will be using the visudo command. This will open up the sudoers file.
To edit the /etc/sudoers file, users need to rectify the entries as per your need. Adding another user to sudo will allow users to execute any command without any password. In the file above, append the following command.
UserName ALL = NOPASSWD: /bin/systemctl restart httpd.service, /bin/kill
Replace the UserName with the name of the user you want to set in the file.
Then, save and exit the file using the Ctl+O shortcut.
Execute ALL sudo commands without a password
For adding a group to sudo without providing a password, use the % character before the name of your group. But first, open up the visudo editor, using the command below:
Once you have opened up the editor window, you need to add the following line in order to add the group and to run all of the commands without a password.
%group ALL=(ALL) NOPASSWD: ALL
Here, replace the group name with the group you want to adjust the settings for.
Allowing a user to run /bin/kill
To allow a user to run the /bin/kill command using the sudo privileges without providing a password, append the following line in the same editor window:
UserName ALL=(ALL) NOPASSWD: /bin/kill
Replace the UserName with the name of the user you want to adjust the settings for.
In the same way, to enable the members of a group to run the sudo commands /bin/kill, /bin/rm without the need of entering any password, run the appended command:
%group ALL=(ALL) NOPASSWD: /bin/kill, /bill/rm
Testing the changes
To test the changes, you can now run the /bin/kill command, which will be used to kill any process whose ID is provided. This time you will not be needing a password:
Conclusion
In this article, we saw the method to run any command without providing the password while using sudo on different Linux platforms. Though it is considered to be risky for security purposes, password-less operations are risky and are an extra feature for secure systems.