The useradd command can be used to create a users account in Linux.
Create user
The useradd command followed by username can be used to create a user account.
useradd john.doe
Change password
The -p or --password option and OpenSSL can be used to create an encrypted password for the user.
useradd --password "$(openssl passwd -1 itsasecret)" john.doe
Or, more commonly, the passwd command is used after the users account has been created.
passwd john.doe
Create home directory
The -m or --create-home or -d or --home-dir options can be used to create the users home directory. In this example, the home directory is /home/john.doe.
useradd --home-dir /home/john.doe john.doe
Create default shell
The -s or --shell option can be used to create the users default shell (/bin/bash in this example).
useradd --shell /bin/bash john.doe
Join a group
The -G or --groups option can be used to add a new user to a group. In this example, john.doe is added to the group named "wheel".
useradd --groups wheel john.doe
Add comment
The -c option can be used to add a comment. The comment is typically the users first and last name.
~]# useradd -c "John Doe" john.doe
View users account
The /etc/passwd file will contain the users account. Refer to Linux Files - Understanding the /etc/passwd file to view the users account.
Did you find this article helpful?
If so, consider buying me a coffee over at