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:
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:
- switch user
If you are currently logged into the system, you can use
su
the 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
sudo
commands to execute commands that require root privileges. Execute the following command > and enter your user password:sudo command
where
command
are 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
zhou
is 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
zhou
should 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
command
are 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
sudo
commands to temporarily grant ordinary users root privileges, rather than adding them to the >sudo
user group. However, this depends on the Linux distribution and configuration. If you are using CentOS 7, CentOS 7 does not have >sudo
user group by default.You can use the following command to add a user to
wheel
a user group, whichwheel
is 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
, pleasezhou
replace 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: