usermod
Overview
The usermod
command modifies user account settings. It allows system administrators to modify various attributes of existing user accounts.
Syntax
usermod [options] LOGIN
Common Options
Option | Description |
---|---|
-a, --append |
Add to supplementary groups |
-c, --comment |
Change comment field |
-d, --home |
Change home directory |
-e, --expiredate |
Set account expiration date |
-g, --gid |
Change primary group |
-G, --groups |
Set supplementary groups |
-l, --login |
Change login name |
-L, --lock |
Lock password |
-m, --move-home |
Move home directory |
-s, --shell |
Change login shell |
-U, --unlock |
Unlock password |
-u, --uid |
Change user ID |
Key Use Cases
- User management
- Access control
- Security maintenance
- Account modification
- Group management
Examples with Explanations
Example 1: Change Shell
usermod -s /bin/bash username
Change user’s login shell
Example 2: Add to Group
usermod -aG sudo username
Add user to sudo group
Example 3: Lock Account
usermod -L username
Lock user account
Understanding Output
- No output on success
- Error messages for:
- Invalid options
- User not found
- Permission denied
- Resource conflicts
Common Usage Patterns
Group management:
usermod -aG group1,group2 user
Home directory:
usermod -d /newhome -m user
Account expiry:
usermod -e 2024-12-31 user
Security Considerations
- Password management
- Group permissions
- Shell restrictions
- Account locking
- Access control
Additional Resources
Best Practices
- Backup before changes
- Document modifications
- Check permissions
- Verify changes
- Regular audits
Common Tasks
- Group management
- Shell changes
- Home directory moves
- Account locking
- Permission updates