- Switch to root user
The method is to directly enter: su on the command line, and then enter the password (that is, your login password, and the password is not visible by default). - The /etc/sudoers file is read-only by default, also for root, so you need to add the write permission of the sudoers file first, the command is:
That is to perform the operation: chmod u+w /etc/sudoers - Edit the sudoers file
That is to execute: vi /etc/sudoers
Find this line root ALL=(ALL) ALL, add xxx ALL=(ALL) ALL below him (where xxx is your username)
ps: Here, you can add any of the following four lines to sudoers
youuser ALL=(ALL) ALL
%youuser ALL=(ALL) ALL
youuser ALL=(ALL) NOPASSWD: ALL
%youuser ALL=(ALL) NOPASSWD: ALL
The first line: Allow the user youuser to execute the sudo command (password required).
The second line: Allow users in the user group youuser to execute the sudo command (password required).
The third line: Allow the user youuser to execute the sudo command without entering a password when executing it.
The fourth line: Allow users in the user group youuser to execute the sudo command without entering a password when executing it.
- To revoke the write permission of sudoers file, command:
chmod u-w /etc/sudoers