How to create a user with password in linux os.

Very simple way. All you have to do is just reading below.

USERNAME=[username]
PASSWORD=[password strings]
sudo useradd -m -p $(openssl passwd -1 ${PASSWORD}) ${USERNAME}

In this command, the useradd command is first used to create a new user. The -m option is used to create the user home directory.
Next, use the -p option to invoke the openssl passwd command to generate a hash of the password. The -1 option instructs the hash to be generated in MD5 format.
Finally, create a new user by specifying a user name. You can now set the password at the same time the user is created.

That’s all.

Leave a Comment