Manually Create a Linux User on CentOS 8 (UID/GID 1024)
This guide walks through manually adding a new Linux user named zhangsan on CentOS 8 by editing /etc/passwd, /etc/shadow, and /etc/group, creating the home directory, setting proper ownership and permissions, creating a mail file, and verifying the account.
Step 1: Edit /etc/passwd
Open /etc/passwd with vim and append a line for the new user. The fields are:
Username
Password placeholder (usually x, real hash stored in /etc/shadow)
UID (set to 1024)
GID (set to 1024)
User description (optional)
Home directory ( /home/zhangsan)
Default shell ( /bin/bash)
Step 2: Edit /etc/shadow
Open /etc/shadow with vim and add a line for the same user. The fields are:
Username
Password hash (use !! or !! to indicate no password)
Days since 1970‑01‑01 of last password change
Minimum days before a password can be changed (0 = any time)
Password expiration period
Days before expiration to warn the user
Grace period after expiration during which login is allowed but password must be changed
Maximum password age
Reserved field
Step 3: Edit /etc/group
Add a line defining the new group (same name as the user) with four fields:
Group name (zhangsan)
Group password placeholder ( x)
GID (1024)
List of members (empty if this is the primary group)
Step 4: Create the Home Directory
mkdir /home/zhangsanStep 5: Populate the Home Directory
Copy the default configuration files from /etc/skel (or use useradd which does this automatically) into the new home directory.
Step 6: Set Ownership and Permissions
# Change owner and group of the home directory
chown -R zhangsan:zhangsan /home/zhangsan
# Restrict permissions so only the owner can read/write/execute
chmod 700 /home/zhangsanStep 7: Create the Mailbox File
# Create an empty mailbox file for the user
touch /var/spool/mail/zhangsan
# Assign correct ownership
chown zhangsan:zhangsan /var/spool/mail/zhangsanStep 8: Verify the User Creation
Check that the entries appear correctly in /etc/passwd, /etc/shadow, and /etc/group, and that the home directory and mailbox belong to zhangsan. You can also run id zhangsan or attempt a login to confirm the account works.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
ITPUB
Official ITPUB account sharing technical insights, community news, and exciting events.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
