Cheatsheet & Examples: useradd
Create a Regular User Account
Example Usage:
useradd john
What it does: Creates a new user account with default settings, including a home directory and default shell.
Command-line Arguments Explained:
-m: Creates the user's home directory if it doesn't exist.-s: Sets the default shell for the new user.-c: Adds a comment field for the user's information.
Create a User with a Specific Shell
Example Usage:
useradd -s /bin/zsh john
What it does: Creates a new user account with the specified shell (e.g., Zsh).
Command-line Arguments Explained:
-s: Specifies the shell path (e.g.,/bin/zsh).
Create a User with a Specific Shell and Home Directory
Example Usage:
useradd -s /usr/bin/irbash -m john
What it does: Creates a new user account with a custom shell and a home directory.
Command-line Arguments Explained:
-s: Specifies the shell path (e.g.,/usr/bin/irbash).-m: Creates the home directory if it doesn't exist.
Add a User with a Comment
Example Usage:
useradd -c "Custom User" john
What it does: Creates a new user account with a custom comment field.
Command-line Arguments Explained:
-c: Adds a comment field for the user.
Set Expiration Date for a User
Example Usage:
useradd -e 2025 john
What it does: Sets the expiration date for the user account.
Command-line Arguments Explained:
-e: Sets the expiration date for the user account (format:YYYY-MM-DD).
Create a User with a Password
Example Usage:
useradd -p <password> john
What it does:
Creates a new user account with a specified password (note: -p is for existing users).
Command-line Arguments Explained:
-p: Sets the password for the user account.

