How to add superuser sudo in CentOS
We can only execute certain commands as the root user using sudo
the command. The root user is also called sudo
a user. In CentOS
, we can add users by adding them to wheel
the group, or by adding them to /etc/sudoers
files under the directory sudo
.
Adding users to wheel
a group
Let's consider that you have a sudo
user that is not a superuser. To add that user to wheel
the group, we run the following command as another already existing superuser.
usermod -aG wheel username
username
is wheel
the name of the user to be added to the group.
usermod -aG wheel zeppy
It zeppy
adds to wheel
the group.
To confirm if the user is added to wheel
the group, we use whoami
the command.
sudo whoami
This command prompts us for a password, and if the password is correct and the user is in wheel
the group, root
it will be printed in the terminal.
Output:
root
If the user is not wheel
in the group, we will get an error message user is not in the sudoers file
.
Adding Users in Sudoers File
Users with sudo
permissions /etc/sudoers
are configured in the config file. We can add users by modifying sudoers
the config file or /etc/sudoers.d
by adding a new configuration file in the config directory sudo
.
We use visudo
the command to edit /etc/sudoers
the file, which uses vim
the editor. visudo
The command checks the file for syntax errors before saving.
To edit the file using nano
editor /etc/sudoers
, we use the following command.
EDITOR=nano visudo
If we want to allow the user to run commands without being prompted for a password sudo
, we use the command to open /etc/sudoers
the file.
visudo
If you get permission denied error, try using the command below.
sudo visudo
Now /etc/sudo
the file will be opened and we need to add the following line at the end of the file.
username ALL=(ALL) NOPASSWD:ALL
Here, username
is the name of the user we want to allow.
Now, we need to save the file before exiting the editor.
We can also allow users to execute only certain commands without a password.
zeppy ALL=(ALL) NOPASSWD:/bin/mkdir,/bin/rmdir
This allows the and commands zeppy
to be executed without a password ./bin/mkdir
/bin/rmdir
We can also /etc/sudoers.d
enable permissions for users to run commands by creating a configuration file under the directory.
We have to add /etc/sudo
the same content in the file as in the .
zeppy ALL=(ALL) NOPASSWD:/bin/mkdir,/bin/rmdir
This allows the and commands zeppy
to be executed without a password ./bin/mkdir
/bin/rmdir
The benefit of this approach is that it makes things a lot easier to manage because we can create a separate file for each user's file name.
For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.
Related Articles
Updating PHP 7.x to 7.4 on CentOS
Publish Date:2025/04/13 Views:131 Category:PHP
-
This article shows the steps to update the PHP version from 7.x version to 7.4 in CentOS. How to Update PHP from 7.X to 7.4 in CentOS Update operating system packages. yum update -y Check your PHP version in CentOS. php -v Prints a list of
Redis installation method and common problem solving under centos
Publish Date:2025/04/09 Views:158 Category:Redis
-
In this article, we will introduce how to install redis under CentOS. In fact, the installation steps are very simple, but there may be some problems in the middle, which is worthy of our attention. Let's take a look at how to install it. F
How to install manpage in centos
Publish Date:2025/04/07 Views:117 Category:OPERATING SYSTEM
-
Usually, centos system comes with man commands, which can be used to view the details of commonly used commands. However, sometimes we need to view some functions, and using only the default man functions cannot meet the needs. At this time
iptables Flush: Delete all rules on RedHat and CentOS Linux
Publish Date:2025/04/07 Views:153 Category:OPERATING SYSTEM
-
On Red Hat based Linux, iptables comes with some default rules. It is a good idea to clean them up and start from scratch. This article is part of the ongoing iptables tutorial series. This is the 2nd article in the series. In our first par
How to install GrayLog on centos
Publish Date:2025/04/06 Views:122 Category:OPERATING SYSTEM
-
Installing Graylog on CentOS requires the following steps: 1. Add EPEL and MongoDB repositories: sudo yum install epel-release -y sudo rpm -Uvh https://repo.mongodb.org/yum/redhat/7/mongodb-org/4.4/x86_64/RPMS/mongodb-org-server-4.4.4-1.el7
How to install Elasticsearch on CentOS
Publish Date:2025/04/06 Views:157 Category:OPERATING SYSTEM
-
Elasticsearch is an open source search engine developed based on Java, so you need to install the Java runtime environment to run it properly. Specifically, Elasticsearch is a distributed search engine built on Apache Lucene. It uses Java t
How to get IP address in CentOS
Publish Date:2025/03/23 Views:109 Category:OPERATING SYSTEM
-
This short article is a brief introduction to CentOS followed by a brief discussion on how we can get the server IP address in CentOS using the Command Line Interface (CLI). This article will discuss some of the commands and their usage for
如何在 CentOS 中获取 IP 地址
Publish Date:2023/05/04 Views:149 Category:操作系统
-
这篇简短的文章是对 CentOS 的一个简短介绍,然后简要讨论了我们如何使用命令行界面 (CLI) 在 CentOS 中获取服务器 IP 地址。
在 CentOS 上将 PHP 7.x 更新到 7.4
Publish Date:2023/03/29 Views:267 Category:PHP
-
本文展示了将 CentOS 中的 PHP 版本从 7.x 版本更新到 7.4 的步骤。