Linux

Do you know how to create a new user without using adduser/useradd command?

Difficulty: unrated

Source: bregman-arie/devops-exercises by Arie Bregman

Answer

YES, we can create new user by manually adding an entry in the /etc/passwd file.

For example, if we need to create a user called john.

Step 1: Add an entry to /etc/passwd file, so user gets created.

echo "john:x:2001:2001::/home/john:/bin/bash" >> /etc/passwd

Step 2: Add an entry to /etc/group file, because every user belong to the primary group that has same name as the username.

echo "john:x:2001:" >> /etc/group

Step 3: Verify if the user got created

id john