Where does Linux keep account data?
In a few plain text files, read through the name service switch:
| File | Holds | Readable by |
|---|---|---|
/etc/passwd | Name, UID, primary GID, comment, home, shell | Everyone |
/etc/shadow | Password hashes, aging and expiry dates | root only |
/etc/group | Group names, GIDs and members | Everyone |
/etc/gshadow | Group passwords and admins | root only |
/etc/login.defs | Defaults: UID ranges, password aging, umask | Everyone |
Query them with getent passwd ana and getent group sudo rather than reading files directly; getent also covers accounts from LDAP or other directories. Edit them only through the tools below, or with vipw and vigr, which lock the files during changes.
Which accounts are people and which are services?
By UID range. Regular users start at 1000 on Ubuntu, Debian and the Enterprise Linux images, and at 1001 on FreeBSD. Lower numbers belong to the system: root is 0, and service accounts such as www-data, postgres or nginx sit below 1000 with shells like /usr/sbin/nologin. List the people quickly:
getent passwd | awk -F: '$3 >= 1000 && $3 < 60000 {print $1, $3, $7}'
How do I create and change accounts?
Creation is covered in detail in Create a Linux user. Changes go through usermod:
usermod -c "Lars Holm, billing team" lars # update the comment usermod -s /bin/zsh lars # change login shell usermod -aG docker,adm lars # add groups, keep existing ones usermod -l lholm -d /home/lholm -m lars # rename and move the home folder
When renaming, also rename the user's primary group with groupmod -n lholm lars so names stay consistent. Run these while the user is logged out; usermod refuses to change some fields for a user with running processes.
How do password aging and expiry work?
chage sets when a password must change and when an account stops working:
chage -l lars # show current settings chage -E 2027-03-31 contractor1 # account expires after that date chage -M 180 -W 14 lars # change every 180 days, warn 14 days ahead chage -d 0 newhire # force a new password at first login
On servers where people log in with SSH keys, password aging matters mostly for sudo passwords. Account expiry is more useful: set it for contractors at creation, and their access ends on its own.
How do I lock someone out without deleting them?
Lock the password and the account, and remember that SSH keys bypass the password:
usermod -L -e 1 lars # lock password and expire the account gpasswd -d lars sudo # remove admin rights
An expired account cannot log in by any method, including keys. To restore, run usermod -U -e "" lars. Locking keeps files and ownership intact, which is handy while someone is on leave or while you audit what an account did.
How do I see who logs in?
who # who is on right now last -n 20 # recent logins and reboots lastlog | grep -v Never # last login per account, where available
Newer releases are moving from the old lastlog file to lastlog2, so the third command depends on the system. The SSH log tells the same story in detail: journalctl -u ssh on Debian and Ubuntu, -u sshd on the Enterprise Linux images.
How do I delete an account properly?
Check for running processes and files elsewhere, then remove:
pkill -KILL -u lars find / -xdev -user lars -not -path '/home/lars/*' 2>/dev/null | head userdel -r lars
-r deletes the home folder and mail spool. Files outside the home stay, owned by a now-orphaned UID; reassign them with chown before deleting, or find them later with find / -nouser. Also remove the person's key from any shared authorized_keys files, sudoers drop-ins and cron jobs, as described in List all cron jobs.
What does a sensible routine look like?
- One account per person, never shared logins.
- Admin rights through the sudo or wheel group only, as in The sudo command.
- Expiry dates on temporary accounts.
- A quarterly review: list human accounts, group members and keys, and remove what nobody can explain.
Keep Reading
Create a Linux user
Create human and service accounts with useradd: home folders, shells, UIDs, groups, expiry, skeleton files and system accounts.
OpenThe sudo command
How sudo decides who may run what, the flags you use daily, safe sudoers rules, logging and the habits that keep root powers contained.
Opensudo vs su
Two ways to act as root: su switches accounts with the target password, sudo grants logged, per-command rights with yours.
OpenLinux file permissions
Read ls -l output, understand owner, group and other bits, umask defaults, ACLs and why root and SELinux sit on top of it all.
OpenFAQ
Quick Answers
As hashes in /etc/shadow, readable only by root.
Use usermod -aG with the group name; without -a the user's extra groups are replaced.
Run usermod -L -e 1 to lock the password and expire the account, which also blocks SSH keys.
Use chage -E with a date, or useradd -e when creating it.
Run userdel -r after stopping their processes and reassigning files they own elsewhere.