usermod
Overview
The usermod
command modifies a user account. It changes various attributes of user accounts including group membership, home directory, and shell.
Syntax
usermod [options] login
Common Options
Option | Description |
---|---|
-a |
Add to groups |
-c comment |
Comment field |
-d home_dir |
Home directory |
-e expire_date |
Account expiry |
-f inactive |
Inactivity period |
-g group |
Primary group |
-G groups |
Secondary groups |
-l login_name |
New username |
-L |
Lock account |
-m |
Move home |
-s shell |
Login shell |
-u uid |
User ID |
-U |
Unlock account |
Configuration Files
File | Description |
---|---|
/etc/passwd | User accounts |
/etc/shadow | Secure accounts |
/etc/group | Group accounts |
/etc/login.defs | System defaults |
/etc/skel/ | Skeleton files |
Key Use Cases
- Account modification
- Group management
- Security control
- Shell changes
- Directory management
Examples with Explanations
Example 1: Add Group
usermod -aG wheel username
Add to wheel group
Example 2: Change Shell
usermod -s /bin/bash username
Change login shell
Example 3: Lock Account
usermod -L username
Lock user account
Common Usage Patterns
Group addition:
usermod -aG group user
Home directory:
usermod -d /new/home -m user
Account lock:
usermod -L user
Security Considerations
- Account access
- Group permissions
- Shell security
- Directory rights
- Password policy
Additional Resources
Best Practices
- Backup before changes
- Check permissions
- Verify groups
- Document changes
- Test access
User Management
- Account updates
- Group changes
- Security controls
- Shell management
- Directory handling
Troubleshooting
- Permission denied
- Group issues
- Directory problems
- Shell errors
- Lock/unlock issues
Common Issues
- Group conflicts
- Home directory
- Shell access
- Account locks
- Permission errors