Linux creates a user and adds it to the sudo user group

Generally, only the root user is available on a new server. Linux is a multi-user and multi-task operating system. For security reasons, you are advised not to use the root user when running the operating system.

1. useradd adduser

  1. Useradd itself is a Linux script that, when useradd XXX is executed, creates a triple-zero user named XXX

    A. No password You need to run the passwd command to set the password

    B. The /home/xxx directory will not be automatically created if no home directory exists

    C. If no login permission is granted, the login cannot be associated with shell

  2. Adduser creates an interactive user that has a home directory and can log into the shell. What happens when you run addUser pengfei.li?

    A. will add one row on the/etc/passwd pengfei. Li: x: 1001-1001:,,,, / home/pengfei li: / bin/bash

    B. The /home/pengfei.li directory will be created as the user’s home directory

2. Grant the sudo permission to the user

Run this command as user root

$ usermod -aG sudo pengfei.li
Copy the code

Or execute it under a user with sudo permission

$ sudo usermod -aG sudo pengfei.li
Copy the code

Usermod Modifies the user

-A can be used only with -g to add a user to an affiliate group

-g Changes the secondary group of a user

Sudo :x:27:pengfei.li sudo:x:27:pengfei.li sudo:x:27:pengfei.li sudo:x:27:pengfei.li

3. Sudo doesn’t use passwords

After step 2, after exiting the shell and logging in again, the user can execute sudo, but each time you have to enter a password, how can you execute sudo without entering a password?

Shell %sudo ALL=(ALL:ALL) NOPASSWD: ALLCopy the code