useradd Command in Linux
Build an AI-First Career, Master the Complete Skillset
Choose from our industry-leading programs designed for career success
Modern Software and AI Engineering Program
Master full-stack development with AI integration
+1000 moreModern Data Science and ML with specialisation in AI
Advanced data science techniques with AI specialization
+1000 moreAdvanced AIML with Specialisation in Agentic AI
Deep dive into AIML with focus on Agentic systems
+1000 moreDevOps, Cloud & AI Platform Engineering
Build and manage AI-powered cloud infrastructure
+1000 moreAI Engineering Advanced Certification by IIT-Roorkee
Premier AI engineering certification from IIT-Roorkee
AI Forward Deployed Engineer Program
Full-stack engineering, production AI and client-facing consulting
+1000 moreOverview
The useradd command in Linux is a powerful tool that allows administrators to create and manage new user accounts on a Linux system. The command provides various options to customize the user account creation process, such as setting up a specific home directory, assigning a default shell, and applying a custom user ID.
Linux useradd Command Syntax
The syntax for the useradd command is as follows:
Where:
- options: The options are flags that can be used to customize the user account creation process.
- username: The desired username for the new user account.
useradd Command Options:
- -c: Add a comment to the user account, usually the user's full name.
- -d: Specify a custom home directory for the new user.
- -g: Assign the new user to an existing group by providing the group name or group ID.
- -G: Assign the new user to multiple supplementary groups, separated by commas.
- -s: Specify a custom default shell for the new user.
- -u: Assign a custom user ID (UID) for the new user.
- -M: Do not create a home directory for the new user.
- -N: Do not create a primary group for the new user.
Example Usages
-
Create a new user with the default options:
Explanation: This command creates a new user named 'john' with the default options, such as a home directory in /home/john and the default shell assigned by the system.
-
Create a new user with a custom home directory:
Explanation: This command creates a new user named 'jane' and specifies a custom home directory at /custom/home/directory.
How Scaler Transformed Careers in Different Fields
Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.
Tips
-
Always use the '-m' option with '-d' to create the specified home directory if it does not exist.
-
To avoid conflicts, make sure to check for existing users with the same name or UID before creating a new user.
Advanced Use Cases of useradd Command in Linux
-
Create a new user with a custom comment, home directory, and shell:
Explanation: This command creates a new user named 'jane', with a custom comment 'Jane Doe', a custom home directory at /custom/home/directory, and the Zsh shell as the default shell.
-
Create a new user and assign to multiple supplementary groups:
Explanation: This command creates a new user named 'john' and assigns the user to multiple supplementary groups: group1, group2, and group3.
-
Create a new user with a custom UID:
Explanation: This command creates a new user named 'jane' and assigns a custom UID of 1500.
Turn Learning into Career Growth
Conclusion
-
The useradd command is a powerful tool for creating and managing user accounts in Linux.
-
Various options allow customization of the user account creation process.
-
Always check for existing users with the same name or UID before creating a new user.