🐧How to Create a Linux User Account and Set Password

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

FilePurpose
/etc/passwdStores user account details
/etc/shadowStores encrypted password
/etc/groupStores 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

How to change Linux user password

$sudo passwd mital

By admin

Leave a Reply

Your email address will not be published. Required fields are marked *