I am a new CentOS Linux system adminstrator. How do I use sudo command without a password on a CentOS Linux systems? I log in as [email protected] and disabled root login for ssh. After login, I need to run some commands as root user. I am the only sysadmin using my CentOS Linux 7 server. How do I run or execute sudo command without a password for a user named marlena under CentOS Linux cloud server?
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.
Adblock detected ?
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:
- 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:
$ 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:
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.