How to sudo without password on CentOS Linux

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 marlena@my-cloud-server-ip 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.

Run sudo without password on CentOS Linux

  1. Backup /etc/sudoers file, run:
    sudo cp /etc/sudoers /root/sudoers.bak
  2. Edit the /etc/sudoers file on CentOS:
    sudo visudo
  3. Run /usr/sbin/rebootcommand without password on CentOS:
    marlena ALL = NOPASSWD: /usr/bin/reboot
  4. Save and exit the file.

How to execute ALL sudo commands without password on CentOS

Type the following command as root user:
# visudo
$ sudo visudo
Append the following entry to run ALL command without a password for a user named marlena:


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


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.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 1 comment so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04

Comments on this entry are closed.

Comments are closed. Still have questions? Post it on our forum