How to Modify User Accounts and Properties on Linux Using usermod
Working with user accounts is a core part of Linux system administration, especially in DevOps, SRE, and IT support roles. The usermod command is a powerful tool used to change various properties of a user account from login names and shell types to password settings and user IDs. This guide covers some essential usermod operations you’ll often encounter in real-world environments. Table of Contents Change User Login Name Modify User ID (UID) Add a Comment to a User Account Change Home Directory (and Move Contents) Modify the User Shell Lock and Unlock User Password Set a Password Expiry Date Change User Login Name usermod -l newusername oldusername Note: This only changes the login name, not the home directory name. Modify User ID (UID) To change the UID of an existing user: usermod -u new id username Add a Comment to a User Account Comments usually include full names or job titles and are visible in /etc/passwd. usermod -c "Cloud Engineer" username This can help other admins understand user roles at a glance. To remove the comment: usermod -c "" username Change Home Directory (and Move Contents) To update a user’s home directory: usermod -d directory username To also move files from the old home directory to the new one: usermod -d directory -m username Best practice: Always use the -m flag if you're migrating user data. Modify the User Shell To assign a non-interactive shell (useful for service or system accounts): usermod -s /sbin/nologin username Lock and Unlock User Password To lock a user’s password (prevent login): usermod -L username To unlock: usermod -U username Set a Password Expiry Date To set an expiration date for the user's password: usermod -e "2025-05-01" username To remove the expiry date: usermod -e "" username Final Thoughts Understanding how to manage users with usermod not only improves system security and organization. It also helps you operate efficiently in production environments. Mastering these basics builds the foundation for more advanced automation and IAM (Identity & Access Management) tasks in DevOps and Cloud Engineering. If you found this helpful, feel free to share it or drop your thoughts below!

Working with user accounts is a core part of Linux system administration, especially in DevOps, SRE, and IT support roles. The usermod command is a powerful tool used to change various properties of a user account from login names and shell types to password settings and user IDs.
This guide covers some essential usermod operations you’ll often encounter in real-world environments.
Table of Contents
Change User Login Name
Modify User ID (UID)
Add a Comment to a User Account
Change Home Directory (and Move Contents)
Modify the User Shell
Lock and Unlock User Password
Set a Password Expiry Date
Change User Login Name
usermod -l newusername oldusername
Note: This only changes the login name, not the home directory name.
Modify User ID (UID)
To change the UID of an existing user:
usermod -u new id username
Add a Comment to a User Account
Comments usually include full names or job titles and are visible in /etc/passwd.
usermod -c "Cloud Engineer" username
This can help other admins understand user roles at a glance.
To remove the comment:
usermod -c "" username
Change Home Directory (and Move Contents)
To update a user’s home directory:
usermod -d directory username
To also move files from the old home directory to the new one:
usermod -d directory -m username
Best practice: Always use the -m flag if you're migrating user data.
Modify the User Shell
To assign a non-interactive shell (useful for service or system accounts):
usermod -s /sbin/nologin username
Lock and Unlock User Password
To lock a user’s password (prevent login):
usermod -L username
To unlock:
usermod -U username
Set a Password Expiry Date
To set an expiration date for the user's password:
usermod -e "2025-05-01" username
To remove the expiry date:
usermod -e "" username
Final Thoughts
Understanding how to manage users with usermod not only improves system security and organization. It also helps you operate efficiently in production environments. Mastering these basics builds the foundation for more advanced automation and IAM (Identity & Access Management) tasks in DevOps and Cloud Engineering.
If you found this helpful, feel free to share it or drop your thoughts below!