Centos add a user and give root privileges

1. Add a user, the command is as follows:

adduser zhangsan

2. To modify the user password, the command is as follows:

passwd zhangsan

The result after execution is as follows:

Changing password for user zhangsan

New password:    

Enter the new password here and press Enter to confirm

Retype new password:  

Enter the new password again, and then press Enter to confirm, the result after execution is as follows:

passwd: all authentication tokens updated successfully.

3. Give the newly added account root privileges

a). Modify the /etc/passwd file and change the user ID to 0. The command is as follows:

vi  /etc/passwd 

Find the line like this:

zhangsan:x:500:500:zhangsan:/home/tommy:/bin/bash

Modified as follows

zhangsan:x:0:500:tommy:/home/zhangsan:/bin/bash

keep

:wq

After logging in with the [zhangsan] account, you will directly obtain the permissions of the root account.

b). Modify the /etc/sudoers file with the following commands:

vi /etc/sudoers 

Find the following line and add a line below root like this:

#Allow root to run any commands anywhere

root    ALL=(ALL)     ALL

Add a line:

zhangsan ALL=(ALL)     ALL

keep

:wq

If prompted for a read-only file (as shown below)

E45: 'readonly' option is set (add ! to override)

perform a forced save

:wq!

After the modification is completed, you can now log in with the [zhangsan] account, and then use the command su - to obtain root privileges to operate.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326117066&siteId=291194637