How to create a user without useradd command

To create a user without useradd command

In Linux, the useradd command is one of the most popular commands for adding a normal user for Linux distribution. On contrary to what one may think, it is really possible to create a user without making use of the useradd command. In this tutorial you' ll get to know the method to create a user without the usage of useradd command.

 

Creating a user

Make an entry of user details in /etc/passwd location, your syntax for the entry must be as follows.

Syntax

username:password:UID:GID:Comments:Home_Directory:Login Shell

 

Add a new entry in /etc/passwd file  by making use of the following action.

[root@localhost ~]# vim /etc/passwd
user1:x:503:503:testuser:/home/user1:/bin/bash

 

 

You will have to create a group with same name. So add a new entry in /etc/group by making use of the following action.

[root@localhost ~]# vim /etc/group
user1:x:503:

 

 

Now, you need to assign a password to the user and for that you shall use the following command.

[root@localhost home]# passwd user1
Changing password for user user1.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.

 

After that, you shall check and see the password by using the following command.

[root@localhost home]# cat /etc/shadow |grep user1
user1:$6$26iFvYjR$tMtV35CcMTMjZKaFGUG4A30drTZIvqdSDkhNW8rG0PQ44U6ij4hLo9/H/Jxrr7QPmgExum2cKMTQayK99uINC1:17494::::::

 

You shall now try to login with your newly created user. Do it the following way.

[root@localhost home]# su user1
bash-4.1$
bash-4.1$
bash-4.1$

 

  You should see [user1@localhost ~]$ instead of bash-4.1$, this is because the newly created user doesn' t have home directory, and you should add .bash files from /etc/skel in the following manner.

[root@localhost home]# mkdir /home/user1
[root@localhost home]# cd /home/user1
[root@localhost user1]# cp -v /etc/skel/.bash* .
`/etc/skel/.bash_logout'  ->  `./.bash_logout' 
`/etc/skel/.bash_profile'  ->  `./.bash_profile' 
`/etc/skel/.bashrc'  ->  `./.bashrc' 

 

You can check out the bash files in the newly copied location by making use of the list command.

[root@localhost user1]# ls -la
total 20
drwxr-xr-x 2 root root 4096 Nov 24 15:26 .
drwxr-xr-x. 4 root root 4096 Nov 24 15:26 ..
-rw-r--r-- 1 root root 18 Nov 24 15:26 .bash_logout
-rw-r--r-- 1 root root 176 Nov 24 15:26 .bash_profile
-rw-r--r-- 1 root root 124 Nov 24 15:26 .bashrc

 

Now, try to switch over to your new user by making use of the following command.

[root@localhost user1]# su user1 
[user1@localhost ~]$

With this, this tutorial comes to an end.

 

 

 

 

 

 

FAQ
Q
otherthan useradd is there any other command to create user?
A
adduser username is also used to create a new user
Q
how to filter manually created user from /etc/passwd?
A
cat /etc/passwd | grep '/home'
Q
is there any graphical method to create user in debian?
A
give the command "users-admin" . It will opens the gui window for user management
Q
what is the purpose of useradd -D?
A
to display content in /etc/default/useradd
Q
what is the purpose of /etc/skel/ ?
A
The /etc/skel/ contains some hidden files which have profile settings and default values for applications. Hence, it serves as a default home directory and user profile. While using useradd -