useradd
Overview
The useradd
command creates new user accounts on Linux systems. It sets up the user’s home directory, shell, and initial group memberships according to system defaults or specified parameters.
Syntax
useradd [options] username
Common Options
Option | Description |
---|---|
-m |
Create home directory |
-d path |
Specify home directory path |
-s shell |
Specify login shell |
-g group |
Specify primary group |
-G groups |
Specify supplementary groups |
-c comment |
Add comment/full name |
-e date |
Set account expiry date |
-f days |
Set password expiry |
-r |
Create system account |
Key Use Cases
- Create new user accounts
- Set up system service accounts
- Batch user creation
- Create users with specific requirements
- Set up development environment accounts
Examples with Explanations
Example 1: Create Basic User
useradd -m -s /bin/bash username
Creates user with home directory and bash shell
Example 2: Create System User
useradd -r -s /sbin/nologin systemuser
Creates system user without login ability
Example 3: Create User with Groups
useradd -m -G wheel,developers username
Creates user and adds to specified groups
Understanding Output
- No output on success
- Error messages for:
- Duplicate username
- Invalid parameters
- Insufficient permissions
- Resource constraints
Common Usage Patterns
Create standard user:
useradd -m -s /bin/bash -c "Full Name" username
Create service account:
useradd -r -s /sbin/nologin -c "Service Account" svcuser
Create user with specific UID:
useradd -u 1500 -m username
Performance Analysis
- Minimal system impact
- Consider using batch creation for multiple users
- Use templates (-k) for consistent setup
- Monitor disk space for home directories