usermod

Modify Existing User Accounts

What Does It Do?

The usermod command modifies existing user accounts on Linux systems, allowing you to change shells, home directories, groups, and other account properties without recreating the user.

Think of usermod like updating an employee's badge or workspace in a company. When someone changes departments, gets promoted, or needs different access, you modify their existing account rather than creating a new one. IT administrators use it to update user shells, move home directories, add users to security groups, lock/unlock accounts, change user permissions, and update user information.

Advertisement

[ Insert Google AdSense Banner Code Here ]

When Should I Use It?

Change User Groups

Add users to new teams or departments without losing their data.

Lock/Unlock Accounts

Temporarily disable accounts for security or compliance reasons.

Move Home Directories

Relocate user files to different partitions or storage locations.

Update Login Shell

Change user shell preferences (bash, zsh, sh, etc.).

Common Commands

cat /etc/passwd

List all users on the system (see current user details).

sudo usermod -s /bin/bash john

Change john's default shell to bash.

sudo usermod -aG sudo alice

Add alice to the sudo group (append, keeps other groups).

sudo usermod -G developers,sudo sarah

Set sarah's groups (replaces all existing groups).

sudo usermod -d /home/john2 -m john

Move john's home directory to a new location.

sudo usermod -L john

Lock john's account (disable login).

sudo usermod -U john

Unlock john's account (enable login).

sudo usermod -c "John Smith" john

Set john's full name or comment field.

IMPORTANT WARNINGS

-G vs -aG: Using -G replaces ALL groups. Use -aG to append (add) groups without removing existing ones.

User must be logged out: Some changes (like moving home directories) require the user to be logged out first.

Always use sudo: The usermod command requires root privileges. Without sudo, modifications will fail.

Try It Yourself

Practice usermod commands in the interactive terminal below: