There are three commands are available in Linux to create an user account.
Have you ever tried to create an user account in Linux using manual method?
I mean to say without using above methods.
If you don’t know how to do that? we are here to help you on this and will show you in details.
As we have mentioned many times that anything can be done on Linux. It is one of the example.
Yes, we can create it. Are you excited to know more it?
To do so, first, we need to find out last created UID and GID information. Once you have these information handy then proceed to next step.
# cat /etc/passwd | tail -1 tuser1:x:1153:1154:Test User:/home/tuser1:/bin/bash
Based on the above output. Last created user UID is 1153 and GID is 1154. To experiment this, we are going to add tuser2
in the system.
Now, add an entry of user details in /etc/passwd. There are seven fields exist and you need to add required details.
+-----------------------------------------------------------------------+ |username:password:UID:GID:Comments:User Home Directory:User Login Shell| +-----------------------------------------------------------------------+ | | | | | | | 1 2 3 4 5 6 7 1- Username: This field indicates the User name. Characters length should be between 1 to 32. 2- Password (x): It indicates that encrypted password is stored at /etc/shadow file. 3- User ID: It indicates the user ID (UID) each user should have unique UID. UID (0-Zero) is reserved for root, UID (1-99) reserved for system users and UID (100-999) reserved for system accounts/groups 4- Group ID (GID): It indicates the group ID (GID) each group should be having unique GID and it is stored at /etc/group file. 5- Comment/User ID Info: It indicates the comment field.This field can be used to describe the user information. 6- Home directory (/home/$USER): It indicates the user's home directory. 7- shell (/bin/bash): It indicates the user's shell.
Add the user information in end of the file.
# vi /etc/passwd tuser2:x:1154:1155:Test User2:/home/tuser2:/bin/bash
You have to create a group with same name. So, add a group details in /etc/group file as well.
# vi /etc/group tuser2:x:1155:
Once you done the above two steps, then set a password for user.
# passwd tuser2 Changing password for the new user tuser2. New password: Retype new password: passwd: all authentication tokens updated successfully.
Finally, try to login with newly created user.
# ssh [email protected] [email protected]'s password: Creating directory '/home/tuser2'. $ls -la total 16 drwx------. 2 tuser2 tuser2 59 Jun 17 09:46 . drwxr-xr-x. 15 root root 4096 Jun 17 09:46 .. -rw-------. 1 tuser2 tuser2 18 Jun 17 09:46 .bash_logout -rw-------. 1 tuser2 tuser2 193 Jun 17 09:46 .bash_profile -rw-------. 1 tuser2 tuser2 231 Jun 17 09:46 .bashrc