[Linux Question Collection 001] How to add users to the sudo group in Linux

The premise of reading the tutorial is that my current Linux user is zhou. When you read the following steps, you can regard Zhou as your current Linux user:
insert image description here

1. Log in to the system as the root user.

In a Linux system, the root user is a superuser with full system administration privileges. To log in to the system as the root user, you can use one of the following methods:

  1. switch user

If you are currently logged into the system, you can use suthe command (for "superuser") to switch to the root user. Execute the following command and > enter the password of the root user:

su -

NOTE: While typing your password, no characters will be displayed in the terminal, but you are actually typing the password. Please enter and confirm the password carefully > correct.

2. Steps to add users to the sudo group

2.1. Method 1

1. Use the sudo command

If your user account has sudo privileges, you can use sudocommands to execute commands that require root privileges. Execute the following command > and enter your user password:

sudo command

where commandare commands that need to be run with root privileges. You will need to enter your current user's password to confirm that you have sudo privileges.

2. Use the GUI

On some Linux systems, you can open the terminal by clicking the Applications menu and selecting Terminal under System Tools. Next, enter the following command:

su -

Under this method, you need to enter the password of the root user.

Note that logging into the system as the root user has very high privileges and needs to be done carefully so that important > files are not accidentally deleted or changed. Therefore, it is recommended that you use root privileges only when necessary.

3. Execute the following command to add the user to the sudo group:

  usermod -aG sudo zhou //zhou是要你授予权限的用户名

where zhouis the username you want to add to the sudo group. Make sure to replace with the actual username you want to add.

4. Reboot the system to apply the changes.

The user zhoushould have been granted sudo privileges. Users can use the sudo command to execute commands that require root privileges. You can test if the user already has sudo privileges by executing:

sudo command

where commandare commands that need to be run with root privileges. If you are asked for a password and the command executes successfully, the user > already has sudo privileges.

Note that granting all permissions to a user may be a security risk, and it is recommended to grant users only the necessary permissions.

2.2, method two, CentOS 7 use the following method

In Linux systems, it is usually to use sudocommands to temporarily grant ordinary users root privileges, rather than adding them to the > sudouser group. However, this depends on the Linux distribution and configuration. If you are using CentOS 7, CentOS 7 does not have > sudouser group by default.

You can use the following command to add a user to wheela user group, which wheelis the default user group with >sudo privileges in many Linux distributions.

usermod -aG wheel zhou \\把zhou换成你当前的用户就可以了

Note: It is assumed that the user you want to add is zhou, please zhoureplace with the user name you actually want to add.

After adding a user to a user group, you need to log out and log back in for the changes to take effect.

You can then test to see if the user has sudo privileges by entering the following command:

sudo echo "hello world"

If the user has sudo privileges, you will be prompted for the current user's password. If authentication is successful, "hello world" is printed. If unsuccessful, a request for a password is prompted.

Mine is showing success:
insert image description here

Guess you like

Origin blog.csdn.net/weixin_64471900/article/details/130439969