Manually add new users to the Linux system

  

Generally speaking, adding users often use the “useradd ” command, the system can add users by default and set UID, GID and other information, in fact, behind this can be manually modified system File implementation.

We know that there are /etc.passwd, /etc/shadow, /etc/group files in the /etc directory. These three files store the user name (UID, GID, home directory, shell version used, etc.) of the system user, user password and user group information in the system. So we manually modify these files to achieve the purpose of adding users.

The steps are as follows: (add suse as an example)

1 /etc.passwd, /etc/shadow, add content in /etc/group. The format can be obtained by viewing the original file.

1 echo "suse:x:527:527::/home/suse:/bin/bash" >> /etc/passwd

2 echo "suse:x :527:" >> /etc/group

3 echo "$1$fegjjfefa$fwlgd8768fUbWF97o./geUnC.:15089:0:99999:7:::" >> /Etc/shadow

3 is more difficult to understand, “fegjjfefa$fwlgd8768fUbWF97o./geUnC” User password generated for MD5 encryption, 15089 is the setup time, 0 is the minimum password period, and 99999 is the maximum password duration. So we have to manually generate such field values. Can be achieved by the following command:

#openssl passwd -1 -salt XXXXXXXX The actual password (8 is not added to -salt XXXXXXXX, passwd -1 is generated by MD5 encryption)

# 15089 represents the number of days from the first year of Linux to the creation of users. Use this command to achieve: z=$[`date'+%s'`/86400] → z=15089

2

Now we still can't log in to new users because there is no home yet Directory

# mkdir /home/suse

#chown -R suse:suse /home/suse (Change the owner group of the home directory and limit the files in this directory to this owner Group)

#chmod 700 /home/suse

But still can't log in at this time, the system does not have the framework information, environment attribute information of this user.

3 Copy the .bash* under /etc/skel to the user's home directory.

# cp /etc/skel/.bash* /home/suse/

Next, you must confirm the permissions of these files, belonging to the main group.

At this point, manually add users to complete, you can log in to the host as suse.

Copyright © Windows knowledge All Rights Reserved