useradd Command in Linux

Learn via video courses
Topics Covered

Build an AI-First Career, Master the Complete Skillset

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program
NSDC Certified

AI Forward Deployed Engineer Program

Full-stack engineering, production AI and client-facing consulting

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program

Overview

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.
Sharpen Your Fundamentals with Free Learning

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

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data
Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more

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

1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary
1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary

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.