https://www.tecmint.com/usermod-command-examples-linux/ via Linux News ( https://goo.gl/Xa2mzf )
usermod changes an existing account. It’s the counterpart to useradd. TecMint’s article “16 usermod Command Examples for Linux User Administration” walks through the common cases. Here is our quick reference for the same tasks, with notes for RHEL, CentOS and AlmaLinux. Run everything as root, and check the result with id user or getent passwd user.
The one mistake to avoid
usermod -G on its own replaces every supplementary group. If you leave out -a, a user can lose wheel, docker and everything else in one command. Always use -aG to add groups.
The 16 tasks
# 1 Set the comment (GECOS) field
usermod -c "Jane Doe, DBA" jdoe
# 2 Change the home path only
usermod -d /data/jdoe jdoe
# 3 Change the home path and move the files
usermod -m -d /data/jdoe jdoe
# 4 Set an expiry date, or clear it with an empty value
usermod -e 2027-06-30 jdoe
usermod -e "" jdoe
# 5 Disable the account 7 days after the password expires
usermod -f 7 jdoe
# 6 Change the primary group
usermod -g developers jdoe
# 7 Add supplementary groups without removing existing ones
usermod -aG wheel,docker jdoe
# 8 Remove the user from one supplementary group
gpasswd -d jdoe docker
# 9 Rename the login (the home directory is not renamed)
usermod -l janedoe jdoe
# 10 Change the login shell
usermod -s /bin/zsh jdoe
# 11 Change the UID, then fix files outside the home directory
usermod -u 2001 jdoe
find / -xdev -user 1001 -exec chown -h 2001 {} +
# 12 Lock and unlock the password
usermod -L jdoe
usermod -U jdoe
# 13 Set a password: use passwd, not usermod -p
passwd jdoe
# 14 Subordinate ID ranges for rootless Podman
usermod --add-subuids 100000-165535 --add-subgids 100000-165535 jdoe
# 15 Map the account to an SELinux user
usermod -Z staff_u jdoe
# 16 Several changes at once
usermod -c "Jane Doe" -s /bin/bash -aG wheel -e 2027-12-31 jdoe
Notes
- Home directory moves: the user must be logged out. On SELinux systems, run
restorecon -Rvon the new path. See Change a Linux User’s Home Directory with usermod -d and -m for a full walkthrough. - Renames: after
-l, runusermod -m -d /home/newname newnameif you also want the home folder renamed, andgroupmod -nto rename the user’s private group. - Locking:
-Lonly blocks password logins. SSH keys still work, so also runusermod -e 1or set the shell to/sbin/nologinto block access fully. - Passwords:
usermod -pexpects an already-hashed value and leaves it in shell history. Usepasswdorchpasswdinstead. - Group changes take effect at the user’s next login.
- Directory users:
usermodonly edits local files. For LDAP accounts, see changing an LDAP user’s home directory.
Source
Based on 16 usermod Command Examples for Linux User Administration (TecMint), with notes from the usermod(8) man page.
Related guides: Change a Linux User’s Home Directory with usermod -d and -m | Change home directory of LDAP user command line

1 Comment