JIYIK CN >

Current Location:Home > Learning > OPERATING SYSTEM >

How to add superuser sudo in CentOS

Author:JIYIK Last Updated:2025/04/05 Views:

We can only execute certain commands as the root user using sudothe command. The root user is also called sudoa user. In CentOS, we can add users by adding them to wheelthe group, or by adding them to /etc/sudoersfiles under the directory sudo.

Adding users to wheela group

Let's consider that you have a sudouser that is not a superuser. To add that user to wheelthe group, we run the following command as another already existing superuser.

usermod -aG wheel username

usernameis wheelthe name of the user to be added to the group.

usermod -aG wheel zeppy

It zeppyadds to wheelthe group.

To confirm if the user is added to wheelthe group, we use whoamithe command.

sudo whoami

This command prompts us for a password, and if the password is correct and the user is in wheelthe group, rootit will be printed in the terminal.

Output:

root

If the user is not wheelin the group, we will get an error message user is not in the sudoers file.

Adding Users in Sudoers File

Users with sudopermissions /etc/sudoersare configured in the config file. We can add users by modifying sudoersthe config file or /etc/sudoers.dby adding a new configuration file in the config directory sudo.

We use visudothe command to edit /etc/sudoersthe file, which uses vimthe editor. visudoThe command checks the file for syntax errors before saving.

To edit the file using nanoeditor /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/sudoersthe file.

visudo

If you get permission denied error, try using the command below.

sudo visudo

Now /etc/sudothe file will be opened and we need to add the following line at the end of the file.

username ALL=(ALL) NOPASSWD:ALL

Here, usernameis 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 zeppyto be executed without a password ./bin/mkdir/bin/rmdir

We can also /etc/sudoers.denable permissions for users to run commands by creating a configuration file under the directory.

We have to add /etc/sudothe same content in the file as in the .

zeppy ALL=(ALL) NOPASSWD:/bin/mkdir,/bin/rmdir

This allows the and commands zeppyto 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.

Article URL:

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

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 地址。

Scan to Read All Tech Tutorials

Social Media
  • https://www.github.com/onmpw
  • qq:1244347461

Recommended

Tags

Scan the Code
Easier Access Tutorial