Operations 6 min read

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.

ITPUB
ITPUB
ITPUB
Manually Create a Linux User on CentOS 8 (UID/GID 1024)

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/zhangsan

Step 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/zhangsan

Step 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/zhangsan

Step 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.

Editing /etc/passwd
Editing /etc/passwd
Editing /etc/shadow
Editing /etc/shadow
Adding group entry
Adding group entry
Final directory permissions
Final directory permissions
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LinuxUser ManagementCentOS
ITPUB
Written by

ITPUB

Official ITPUB account sharing technical insights, community news, and exciting events.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.