id, getent, and passwd -S. By the end you’ll understand the common user-management commands (useradd, usermod, userdel) and the system changes they produce.
Note: these examples assume you are running as the root user. If you are not root, prefix the commands with sudo.
Resources:
- useradd, usermod, userdel: useradd(8) / usermod(8) / userdel(8)
- Check groups and passwd entries:
getent(seegetent passwd,getent group)
Verify accounts and system files
Use these commands to inspect accounts and groups:- Show user identity and groups:
- Lookup user entry in system databases (works with NSS like LDAP):
- Check
/etc/passwdand/etc/groupdirectly (local files):
Create users
- Create a basic user
user1(no home by default on some distros):
id output (UID/GID numbers vary):
- Create
user2with a custom home directory and ensure the home is created (-mand-d):
- Create
user3with a specific UID:
- Create a non-login/system-style account
user4by setting the shell to/sbin/nologin:
- Create
user5with an existing primary groupstudent(thestudentgroup must already exist):
student has GID 1000):
- Create
user6and add it to thewheelgroup as a supplementary group:
wheel membership (UID/GID numbers may differ):
Modify users
Useusermod to change existing accounts.
- Rename
user1tonewuser1:
-d and -m:
- Add
user2to thewheelgroup without removing existing supplementary groups (append with-aG):
- Change the login shell for
user5to/bin/bash:
- Lock
user4to disable password-based logins:
passwd -S output after locking (format varies by distro):
Provide default files for new users
Files in/etc/skel/ are copied into new users’ home directories when you create homes with useradd -m.
- Create a welcome file in
/etc/skel/:
- Create a new user
user7to test that thewelcomefile is copied:
/home/user7/welcome and the message you added.
Delete users
- Delete
user4(removes only the user account, not the home directory):
- Delete
user5and remove its home directory and mail spool (-r):
Quick reference — common options
Summary
useradd— create user accounts. Useful options:-m,-d,-u,-s,-g,-G.usermod— modify existing accounts. Common options:-l,-d -m,-s,-aG,-L.userdel— remove accounts; add-rto delete home directories and mail spools.- Put default files in
/etc/skel/to have them copied into new users’ homes when usinguseradd -m. - Verify accounts with
id,getent passwd,getent group, or by inspecting/etc/passwdand/etc/group.
Always ensure any groups you reference (for example
student or wheel) exist before assigning them as primary or supplementary groups. Use getent group <groupname> to check.