What is the useradd Command?
The word useradd means adding a user, that is, creating a new user account in the system. Whenever someone needs access to a file or system resource, the administrator uses this command to create a new user account. The administrator can also create a group and add users to it to control access. This command helps organize users and groups and assign appropriate permissions.
Syntax:
useradd [options] username
Example 1: Create a simple user
Command:
useradd shobha
Output:
(no output if successful)
Example 2: Create a user with a home directory
Command:
useradd -m prabha
Output:
(no output if successful)
But you will be checking it.
ls /home
Output:
prabha shobha
Here, the command creates a new home directory for Prabha.
Example 3: Create a user with a specific shell
Command:
useradd -s /bin/bash ravi
Output:
(no output if successful)
To check it:
cat /etc/passwd | grep ravi
Output:
ravi:x:1003:1003::/home/ravi:/bin/bash
Example 4: Error Case
Command:
useradd shobha
Output:
useradd: user 'shobha' already exists
Options:
- -m → If you use this option with the command, it creates a home directory for the user.
- -d /path/to/home → If you use this option with the command, it sets a custom home directory for the user.
- -s /bin/bash → If you use this option with the command, it sets the default shell for the user.
- -u UID → If you use this option with the command, it assigns a specific user ID (UID) to the new user.
- -g GROUP → If you use this option with the command, it assigns a primary group to the new user.
- -G GROUP1, GROUP2 → If you use this option with the command, it assigns the user to additional (secondary) groups.
- -c "comment" → If you use this option with the command, it adds a description or comment for the new user.
- -e YYYY-MM-DD → If you use this option with the command, it sets an expiration date for the user account.
- -f DAYS → If you use this option with the command, it specifies the number of days after a password expires until the user account is disabled.
- -p PASSWORD → If you use this option with the command, it sets the encrypted password for the new user.












