Summary of linux Method for Adding root Permission to User

  • 2021-07-22 12:19:43
  • OfStack

1. To add a user, first add an ordinary user with the adduser command. The command is as follows:

#adduser tommy
//Add 1 user named tommy
# passwd tommy//Change password
Changing password for user tommy.
New UNIX password://Enter the new password here
Retype new UNIX password://Enter new password again
passwd: all authentication tokens updated successfully.

2. Give root permission

Method 1: Modify the/etc/sudoers file, find the following line, and remove the previous comment (#)

## Allows people in group wheel to run all commands
%wheel ALL=(ALL) ALL

Then modify the user to belong to the root group (wheel) with the following command:

#usermod -g root tommy

After modification, you can now log in with tommy account, and then use the command su-to obtain root permission to operate.

Method 2: Modify the/etc/sudoers file, find the following 1 line, and add 1 line under root as follows:

## Allow root to run any commands anywhere
root ALL=(ALL) ALL
tommy ALL=(ALL) ALL

After modification, you can now log in with tommy account, and then use the command su-to obtain root permission to operate.

Method 3: Modify the/etc/passwd file, find the following line, and modify user ID to 0, as follows:

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

It is amended as follows

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

Save, after logging in with tommy account, you can directly obtain the authority of root account.

Friendly reminder: Although method 3 looks simple and convenient, it is generally not recommended to use, and method 2 is recommended.

linux How to Add root Permissions to User

## Allow root to run any commands anywhere

root ALL=(ALL) ALL

tommy ALL=(ALL) ALL

After modification, you can now log in with tommy account.

Then use the command su to obtain root permission to operate.

The above is all the relevant knowledge points introduced this time. Thank you for your study and support for this site.


Related articles: