Creating a user with password in online


You can use the below command line combination:
Code:
useradd USERNAME && echo PASSWORD | passwd USERNAME--stdin
Example:
Code:
[root@devopsrun1 ~]# useradd testuser && echo testuser-password | passwd testuser --stdin
Changing password for user testuser.
passwd: all authentication tokens updated successfully.

Creating a user with password, with predefined values


Predefine username and passwords in variables.
Example:
Code:
[root@devopsrun1 ~]# user=newuser
[root@devopsrun1 ~]# pass=newpassword
[root@devopsrun1 ~]# useradd $user && echo $pass | passwd $user --stdin
Changing password for user newuser.
passwd: all authentication tokens updated successfully.

Verifying whether the user accounts have been created


Let us look into the last 2 lines of /etc/passwd to verify it.
Code:
[root@devopsrun1 ~]# tail -2 /etc/passwd
testuser:x:1003:1004::/home/testuser:/bin/bash
newuser:x:1004:1005::/home/newuser:/bin/bash

Final step: Delete test user accounts


Code:
[root@devopsrun1 ~]# userdel -r testuser
[root@devopsrun1 ~]# userdel -r newuser