Linux requires knowledge about terminal and commands and unlike Windows 10 you can do everything with a bunch of keystrokes. Adding users in Linux is rather simple but command based. In this article, we will see how to create user with password on Linux and one line commands to add a user with password’.
When we talk about Linux, the first thing to consider is Ubuntu, which is a fairly popular operating system. Apart from this, many operating systems are based on Ubuntu since there are segments of people who don’t like the way Ubuntu works and looks. Some operating systems are such that are made for very specific users such as Elementary OS.
Whatever new user account you create, a new folder creates under /Home/username.
Add a user to Linux the usual way.
For this, you will have to open the terminal. You can open the terminal by going to the Task Bar — you will find the terminal app in applications list. There are some shortcuts that you can use to open the terminal window.
When the terminal window opens, you have to type the comment given below following by a username.
useradd [username]
replace username with something more human.
The new user account has to be secured, so it’ll be locked which require you to set a new password.
passwd [password]
This command will set given password for the user you created.
Example, I would like to have a new user account with the name “Devendra” and “qf007” password.
# useradd Devendra
# passwd qf007
Read next: How To Setup C++ Development Environment In Linux
Available options.
- -c comment: Add a comment for user.
- -e yyyy-mm-dd: Date for the account to be disabled
- -f days: Set expiration date 0 to disable account with password expiration. -1 for not disable the account.
- -M: Do not create the home directory
Load more options you can choose by typing the command.
$ man adduser
Linux add user with password one line
Linux users are demanding, many would ask for one line command to add username with password and fortunately, there is a way to do this.
In Linux, useradd is used to configure everything including username and password. For security reasons, the password should in encrypted, and you can use openssl for making md5 passwords, this helps to specify the password if it’s in plain text.
useradd -u ABCDE -g users -d /home/username -s /bin/bash -p $(echo mypasswd | openssl passwd -1 -stdin) username
-u userid
-d groupname
-d user home directory
-s default shell
-p password
Openssl passwd will generate hash of mypasswd to be used as secure password.
To exclude this from history, unite a space before the command to prevent is from history. If you have to do the corresponding on lots of machines, generate the password once and type in the command.
useradd -u 12345 -g users -d /home/username -s /bin/bash -p '$1$NNfXfoym$Eos.OG6sFMGE8U6ImwBqT1' username
adduser --uid 3434 --password my_password my_login
Conclusion
Pretty much everything was given in this article to create a user with password in Linux, even with a single line code-that’s something. If you like Linux, hop on and subscribe to our channel. Do you have more Linux tips, why not comment down them, below.
For Ubuntu:
adduser –quiet –gecos “” –disabled-password $USER && chpasswd <<< "$USER:$PASS"
OR
adduser –quiet –gecos "" –disabled-password username && echo 'username:Secr3TPass' | chpasswd
adduser is totally different from useradd,
you’re confusing others when showing the man page of adduser while using useradd instead.
Hello, can you please comment a fix?
adduser –quiet –gecos “” –disabled-password username && echo ‘username:Secr3TPass’ | chpasswd
OR
USER=username
PASS=’Secr^3TPass’
adduser –quiet –gecos “” –disabled-password $USER && chpasswd <<< "$USER:$PASS"