Get the App
SLTechnology News&Howtos  ›  Servers  › 

CentOS how to add users to sudoer list tutorial

Shulou Source: shulou.com Published: 2022-06-01 14:34:59 10月12日 Update

This article introduces the knowledge of "CentOS how to add users to sudoer list tutorial". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

CentOS adds users to the sudoer list

CentOS

By default, linux does not include the current user in the sudoer list (most common in linux distributions of the redhat series), and if you use sudo to execute certain commands, you will be prompted that the user is no longer in the sudoer list. At this point, we need to join by hand.

1. At the command line, type: $su, and enter the password of the root account, switch to the root account, where $is the command prompt, do not need you to type

two。 Type: # visudo on the command line, and the configuration file for sudo will open.

Any configuration file under linux is saved as a text file, that is, you can use vim to open the sudo configuration file, but this is not recommended, because your visudo is the tool provided by linux to modify the sudo configuration file, compared with vim, it will provide more tips and error correction capabilities.

3. Just like editing a text file with vim, we search for the root keyword, so type / root in the open file

4. Pressing the n key on the keyboard automatically jumps to the keyword of the next root, all the way to this sentence:

# # Allow root to run any commands anywhereroot ALL= (ALL) ALL

At this point, continue to press the n key, and the cursor will appear over root in root ALL= (ALL) ALL

5. Enter yyp and enter, which are two commands in vim. Yy means to copy the current line, and p means to paste the copied content to the next line, so after entering the command, the original text becomes as follows:

# # Allow root to run any commands anywhereroot ALL= (ALL) ALLroot ALL= (ALL) ALL

6. Press the j key, the cursor will jump to the second root ALL= (ALL) ALL this line, and then press the number 0 key, let the cursor back to the beginning of the line, then press 4 x keys to delete the four letters root of this line. Then press the I key to enter insert mode and enter your user name, for example, my current user name is xin, then I enter xin. After input, the original text is changed to the following:

# # Allow root to run any commands anywhereroot ALL= (ALL) ALLxin ALL= (ALL) ALL

7. Press the ESC key (upper-left corner of the keyboard, on the left side of F1) to launch insert mode, then press: wq three characters to exit and save the current configuration file.

8. Now that the modification is complete, the user xin has been added to the list of sudoer, and you can use the user xin to execute the sudo command.

This is the end of the tutorial on how to add users to CentOS's sudoer list. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Users files commands input configuration one line cursor content more tips tutorials keywords situations text text patterns knowledge accounts keyboards Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Redmi Microsoft Shulou Information Linux