add user without using useradd command in Linux Ultimate Trick
Creating / add user without using useradd command not an good suggestion but still required in few cases. In this article we are going to discuss how to add user without using useradd command.
First we have to know background process of useradd command, when we type useradd <user name> what happens..?
Add user without using useradd command in Linux Ultimate Trick
- Adds an entry to /etc/passwd file
- Creates an group with same user name
- passwd <user name> generate password and add to /etc/shadow file
- If you add user to groups and create group password then it add an entry in /etc/gshadow file
- Very important one is all the files from /etc/skel directory copied to user’s home directory
We are going to do same process manually.
Note: You must be logged in as root / super user.
1Step: Add entry in /etc/passwd file
[root@Arkit-Serv ~]# cat /etc/passwd |grep ravi ravi:x:1001:1001:RHEL7 User:/home/ravi:/bin/bash
2Step: Create group as like user name by adding entry in /etc/group file
[root@Arkit-Serv ~]# cat /etc/group |grep ravi ravi:x:1001:
3Step: Generate Encrypted password using openssl
Generate encrypted password using openssl command, if you see command is not found then try to install using yum install openssl* after that add encrypted password to /etc/shadow file.
[root@Arkit-Serv ~]# openssl passwd -1 -salt xyz Password $1$xyz$3xzWDtsGgf1NhmC9wAuk81 [root@Arkit-Serv ~]# cat /etc/shadow |grep ravi ravi:$1$xyz$3xzWDtsGgf1NhmC9wAuk81/Ke/:17120:0:99999:7::: [root@Arkit-Serv ~]# cat /etc/gshadow |grep ravi ravi:!::
4Step: Make User home directory manually
User profile and his home directory path to be created manually using below commands.
[root@Arkit-Serv ~]# mkdir -p /home/ravi
[root@Arkit-Serv ~]# chown ravi:ravi /home/ravi
5Step: Copy Required profile files from /etc/skel to user home path
[root@Arkit-Serv ~]# cd /etc/skel/ [root@Arkit-Serv skel]# cp -v .* /home/ravi/ ‘.bash_logout’ -> ‘/home/ravi/.bash_logout’ ‘.bash_profile’ -> ‘/home/ravi/.bash_profile’ ‘.bashrc’ -> ‘/home/ravi/.bashrc’
That’s it user created successfully. Login to user and enjoy.
[root@Arkit-Serv ~]# su - ravi [ravi@Arkit-Serv ~]$ who am i root pts/0 2016-12-29 02:03 (192.168.154.1) [ravi@Arkit-Serv ~]$
User Administration create and Manage users in RHEL 7 / Centos 7
How to reset root user password see here
Thanks for your wonderful Support and Encouragement