In Linux, we have a root user created by the system administrator and normal users, which are also created by the system administrator.
However, root user have more privileges than normal user accounts, which is why we suggest letting other people have normal user accounts instead of directly having a root account.
It will restrict them from doing a lot of miscellaneous and unintentional damage to the system, and you can also create users with an expiry date, limited permissions, and many more.
Also remember that only the root user or a user with sudo privileges has access to create a new normal user account in Linux.
|Creating Normal Users
|Root or Sudo Privileges
|Ubuntu, Manjaro, Fedora, etc.
Basic information you must know
adduser commands are used to create users in a Linux system.
useradd command is a compiled binary and available in all Linux distributions; however,
adduser is a Perl script that utilizes the
useradd command to provide more rich features.
Creating a new account will populate the “
/etc/group“, and “
Creating a Normal User
Specify the username in the following command to create a normal user account.
$ sudo useradd [USERNAME]
Set Password to New User
A newly created user has an empty password that can be set using the passwd command.
$ sudo passwd [USERNAME]
Retype new password:
Assign New User to Group
After creating a user, if you want to assign that user to a group like sudo, specify the name of that group and username as shown.
$ sudo usermod -aG sudo [USERNAME]
Creating a Normal User with a Different Home Directory
Create a new directory at the “
/home/” location and specify it to the following command to use it as the default home directory for your new user.
$ sudo useradd -d /home/[DIRECTORY-NAME] [USERNAME]
Creating a New User with a Specific User ID
You can specify a user ID for your newly created user in the range of 100 to 999, as shown.
$ sudo useradd -u 666 [USERNAME]
Creating a New User with a Specific Group ID
If you want to add your current user ID as group to the new user account than find out its ID by reading the “/etc/passwd” file and specify it to the following command.
$ sudo useradd -g [CURRENT-USER] [USERNAME]
Creating a New User without a Home Directory
Assign the “
-M” flag to create a new user without a home directory, but in the next login, the root home directory or previous user’s home directory will be used as the default home directory for that user.
$ sudo useradd -M [USERNAME]
Creating a New User with an Account Expiration Date
To remove the new user account at a specified date, specify that date to the following command with username and the “
$ sudo useradd -e 2023-12-26 [USERNAME]
Creating a New User with a Password Expiry Date
The same password for the long run can be easily breached, so set the password expiry days after which users will be forced to change their password on that specific day.
$ sudo useradd -f [NUMBER-OF-DAYS] [USERNAME]
If you specify “
[NUMBER-OF-DAYS], you will be forced to change your password after 5 days.
Creating a New User with Custom Comments
Comments are helpful to let you know the purpose of that user account or a few details related to that account, which can be easily set using the “
$ sudo useradd -c "This is my comment" [USERNAME]
Creating New User with a Different Login Shell
By default, the bash shell is used by most Linux distributions, which will be the default shell for a new user, although you can easily install another shell like ZSH or Fish and specify this shell as the default for the new user account.
$ sudo useradd -s /bin/zsh [USERNAME]
Execute the “
echo $0” command to find the path of the current shell.
Removing a New User Account
In case you accidentally created a new user without any intention to use it further, you can remove it using the following command:
$ sudo userdel [USERNAME]
That’s all the possible ways to create a new user in Linux; if you have more, feel free to share them in the comment section.