The sudo (“superuser do”) is nothing but a tool for CentOS Linux systems to run commands as another user. Typically as a root user. You can delegate common tasks such as reboot the server or restart the Apache or make a backup using sudo for unprivileged users. By default, sudo needs that a user authenticates using a password before running a command on CentOS 7. Some times you may need to run a command with root privileges, but you do not want to type a password using sudo command. This is useful for scripting or any other purpose. This can be achieved by editing /etc/sudoers file and setting up correct entries. You need to consider any security consequence of allowing a sudo command execute without a password on a CentOS 6 or 7.
Run sudo without password on CentOS Linux
- Backup /etc/sudoers file, run:
sudo cp /etc/sudoers /root/sudoers.bak - Edit the /etc/sudoers file on CentOS:
sudo visudo - Run /usr/sbin/rebootcommand without password on CentOS:
marlena ALL = NOPASSWD: /usr/bin/reboot - Save and exit the file.
How to execute ALL sudo commands without password on CentOS
Type the following command as root user:
# visudo
Or
$ sudo visudo
Append the following entry to run ALL command without a password for a user named marlena:
marlena ALL=(ALL) NOPASSWD:ALL
Save and close the file in vim. It is also possible to grant access to the group name such as sysadm. Any member of sysadm group can run command without a password. The syntax is
%sysadm ALL=(ALL) NOPASSWD: ALL
Of course, you can force the sysadm group to run only given commands such as /usr/sbin/reboot and systemctl:
%sysadm ALL=(ALL) NOPASSWD: /usr/sbin/reboot, systemctl
Here is my sample config file:
Conclusion
You learned how to run ‘sudo’ command without entering a password in CentOS Linux using various configuration options. For more information see sudo command man page here.
🐧 1 comment so far... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
Comments on this entry are closed.
If you still need help regarding sudo and CentOS, try our forum thread here.