useradd
Overview
The useradd
command creates new users or updates default new user information. It is a low-level utility for adding users.
Syntax
useradd [options] login
Common Options
Option | Description |
---|---|
-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 |
-m |
Create home |
-M |
No home directory |
-N |
No user group |
-p password |
Encrypted password |
-r |
System account |
-s shell |
Login shell |
-u uid |
User ID |
Configuration Files
File | Description |
---|---|
/etc/passwd | User accounts |
/etc/shadow | Secure accounts |
/etc/group | Group accounts |
/etc/default/useradd | Defaults |
/etc/login.defs | System defaults |
/etc/skel/ | Skeleton files |
Key Use Cases
- User creation
- Account setup
- System accounts
- Group management
- Security setup
Examples with Explanations
Example 1: Basic User
useradd username
Create basic user
Example 2: Full Setup
useradd -m -G wheel -s /bin/bash username
Create with home and group
Example 3: System User
useradd -r -s /sbin/nologin sysuser
Create system account
Common Usage Patterns
Standard user:
useradd -m -s /bin/bash user
System account:
useradd -r service
Group member:
useradd -G group1,group2 user
Security Considerations
- Password policy
- Group access
- Shell restrictions
- Home directory
- File permissions
Additional Resources
Best Practices
- Strong passwords
- Proper groups
- Shell security
- Directory permissions
- Documentation
User Management
- Account creation
- Group assignment
- Home directories
- Shell setup
- Password policy
Troubleshooting
- Permission denied
- Group issues
- Home directory
- Shell problems
- Password errors
Common Issues
- UID conflicts
- Group access
- Directory rights
- Shell access
- Password setup