Add users manually in linux - understand useradd

1. Understand the configuration files closely related to users:

        /etc/passwd : stores some basic information of all users on the system, such as username, UID, GID, home directory and default shell, etc.

        /etc/shadow : Stores the passwords of all users on the system (encrypted form) and some account security-related settings, such as password change dates, etc.

        /etc/group : Stores information about all user groups on the system. Each line contains a group name, the group's GID, and a list of users who belong to the group.

        These three profiles are the ones most closely related to the user, but there are some other related profiles:

        /etc/login.defs: Stores default parameters related to login, such as account lockout time, password policy, etc.

  /etc/default/useradd: Stores default parameters for creating new users, such as home directory location, default shell, etc.

  /etc/skel: The files and directories that are automatically copied when new users are created are stored under the directory.

        /etc/spool/mail: store user's mailbox    

2. The background work of the user command:

 

3. Configuration steps ( using super administrator privileges )

        3.1 vim /etc/passwd

                Enter the file, first add some basic information of the user, I will name the name of the user to be added as jack

                

 

                 Annotation for each column of user information:

Borrow online​​​​

         3.2 vim /etc/shadow

                Enter the file, set the user password, user password usage time, expiration reminder and other information

       

                 Notes for each column:     

borrow online

         3.3 vim /etc/group

                Configure the main group of jack Configure the main group of jack as wudangpai

                        

                Annotation for each column:

                

borrow online

         3.4 Create a new home directory

mkdir /home/jack

        3.5 Copy the environment variable initialization script to the home directory

cp /etc/skel/.*  /home/jack/

        3.6 Create a new mailbox

​touch  /var/spool/mail/jack

        3.7 Modify the permissions related to the home directory

chown  jack:wudangpai  /home/jack/
chmod 700  /home/jack/

        3.8 Modify mailbox-related permissions

chmod  660 /var/spool/mail/jack
chown  jack:mail  /var/spool/mail/jack
​

        After completing the above steps, a common user is successfully created manually

        3.9 Testing

                You can use the su - jack command to switch to the jack user

4. shell start

        4.1 Two ways to start the shell

        

         4.2 Differences between shell startup configuration files

        

 5. Pay attention

        Before modifying these configuration files, it is strongly recommended to back them up. In general, these files can be automatically updated through commands that manage a user (eg useradd, , passwdand , usermodetc.).

Guess you like

Origin blog.csdn.net/m0_53891399/article/details/130936338