Creating a user in Linux is done using terminal commands. You must have root or sudo privileges.
🟢 1️⃣ Create a New User Account
🔹 Command:
sudo useradd username
📌 Example:
sudo useradd student1
👉 This creates the user, but:
- No password is set yet
- Home directory may not be created (depends on system settings)
🟢 2️⃣ Create User with Home Directory
Recommended method:
sudo useradd -m student1
Options:
-mโ Create home directory-dโ Specify custom home directory-sโ Specify login shell
Example:
sudo useradd -m -s /bin/bash student1
🟢 3️⃣ Set Password for User
After creating user, set password using:
sudo passwd student1
You will be asked to:
- Enter new password
- Re-enter password
If successful:
passwd: password updated successfully
🟢 4️⃣ Using adduser (Recommended in Ubuntu)
In Ubuntu systems, use:
sudo adduser student2
👉 This command:
- Creates home directory
- Sets password
- Asks for full name and details
- More user-friendly than
useradd
🟢 5️⃣ Check User Created
cat /etc/passwd
or
id student1
🟢 6️⃣ Switch to New User
su - student1
or
login student1
🟢 7️⃣ Important User Files
| File | Purpose |
|---|---|
/etc/passwd | Stores user account details |
/etc/shadow | Stores encrypted password |
/etc/group | Stores group information |
how to create user in linux
$sudo adduser mital
Verification
$cat /etc/passwd
You can also use the getent command to verify that user account added to the system:
$getent passwd mital
How to delete a user account
$sudo userdel mital