How to Modify Linux Accounts with usermod

The usermod (user modify) command is a core administrative utility in the Linux operating system designed to alter existing user account properties. Operating with superuser (root) privileges, this command updates system files such as /etc/passwd, /etc/shadow, and /etc/group directly from the terminal without requiring manual file editing. This guide explains how usermod functions internally to modify user accounts, detailing its primary syntax and the standard options used to update account attributes, manage group memberships, relocate home directories, and control account security.

How usermod Works Under the Hood

When a user account is created, Linux stores account properties across several key files:

The usermod command parses the options supplied by an administrator, performs integrity and validation checks (such as verifying that a target UID or group exists), and safely applies the updates directly to these files.


Managing User Identification and Names

To change a user's login name, use the -l (login) flag. This updates the username in /etc/passwd while keeping the user's UID intact:

sudo usermod -l new_username old_username

To alter the unique numeric identifier (UID) assigned to an account, use the -u flag:

sudo usermod -u 1500 username

Note: Modifying a UID with -u automatically updates the ownership of files residing in the user's home directory, but files located elsewhere on the filesystem will retain the old UID and require manual ownership correction.


Managing Group Memberships

Users belong to one primary group and can belong to multiple supplementary groups.


Relocating the Home Directory and Changing Default Shells


Managing Account Security and Expiration

usermod provides flags to manage login capabilities directly within /etc/shadow: