userdel
Overview
The userdel
command deletes a user account and related files. It removes the user from the system, optionally including their home directory and mail spool.
Syntax
userdel [options] LOGIN
Common Options
Option | Description |
---|---|
-f, --force |
Force removal |
-r, --remove |
Remove home directory and mail spool |
-Z, --selinux-user |
Remove SELinux user mapping |
-h, --help |
Display help |
--version |
Show version |
Key Use Cases
- User removal
- System cleanup
- Security maintenance
- Account management
- Resource recovery
Examples with Explanations
Example 1: Basic Usage
userdel username
Delete user account
Example 2: Remove Home
userdel -r username
Delete user and home directory
Example 3: Force Removal
userdel -f username
Force user deletion
Understanding Output
- No output on success
- Error messages for:
- User not found
- Permission denied
- Process running
- Resource busy
Common Usage Patterns
Safe removal:
userdel -r username
Force deletion:
userdel -f -r username
Check before delete:
id username && userdel username
Security Considerations
- Data backup
- Process termination
- File ownership
- Group membership
- Access removal
Additional Resources
Best Practices
- Backup user data
- Check running processes
- Verify group memberships
- Document removal
- Regular audits
Cleanup Tasks
- Home directory
- Mail spool
- Cron jobs
- Print jobs
- System files
Safety Checks
- Active processes
- Owned files
- Running services
- Scheduled tasks
- System dependencies