We often use the sudo command under the ordinary user, in order not to switch the root user frequently, we can add ordinary users to sudoers inside. Linux defaults to not adding users to the Sudoers list, and requires root to manually add the account to the Sudoers list for the normal account to execute the sudo command. The following actions are listed in the centOS6.9 system
One. Switch the login account to the root account
1. Click the user name in the upper-right corner and click the switch user in the drop-down list.
2. In the switch user interface, click Other
3. Enter root, then enter the password to enter the root user
Two. Add the original normal user to sudoers under root user
1. Open terminal, type Visudo
In the text that appears, type/root, looking for the line shown below
Root all= (All) all
After you find this line as shown above, hover the cursor over this line, type yy to copy, and then type P, which will be automatically pasted on the next line
2. Hover the cursor over the root of the copied line, type CW (to replace root), type the account name you want to add, such as: Eric, the result is shown below
Root all= (All) all
Eric All= (All) all
3. Free use of sudo
If you do not need to enter a password when you want to execute the sudo command later, you can type NOPASSWD before the all value of the line copied above: The result is shown below
Root all= (All) all
Eric All= (All) Nopasswd:all
4. Save exit, edit complete, press ESC on the keyboard, exit Insert mode, enter command line mode
Then type: Wq to save the exit
5. Switch back to normal user attempt to execute sudo command
Type the sudo space directly at the front of the command, such as Sudo shutdown-h now to perform an immediate shutdown command.
Note: If the user is not in the Sudoers list, you will get the following prompt.
Eric is isn't in the sudoers file. This incident would be reported.
Add a normal user to sudoers in a Linux system