Here’s how to use the useradd command on Linux, which allows you to quickly create new users from your terminal.
What Is the useradd Command?
The useradd command in Linux is the standard command that is used to add new users. While most of the Linux distributions use the useradd command, some of them including Ubuntu have the adduser command for managing users.
The primary difference between these two commands is that useradd is the default command provided in the base Linux package whereas adduser is just a reference command for useradd.
Distributions such as Ubuntu have created a new command adduser which is connected with the default useradd command via a symbolic link. A symbolic link is a file that stores a reference of any other file on your system.
You can say that useradd and adduser are the same command but with a different name. The useradd command is used on every Arch-based distribution while adduser is used on Ubuntu.
Standard and Elevated Users
Before hopping on to your terminal, you should learn about the types of users that you can create on Linux. There are three fundamental user types on a Linux system.
Administrative (Root) Regular Service
Each of these users have specific permissions and set of commands that they can execute.
For example, the system creates the root user automatically when you install Linux on a computer. These users have permissions associated with all the administrative tasks and services on a Linux system. They can delete system files, install new packages, create new users, delete existing users, and more.
On the other hand, regular users have the authorization to execute standard tasks on the system. A regular user can perform simple tasks such as copying files with the cp command, browsing the internet, and playing games. These users may or may not have their own “home” directories for storing files.
In Linux systems, each application has its own service accounts that are provided to regular users. Service users are assigned with permissions related to such applications. You can also provide a user with other privileges by referencing the user with its User ID (UID).
Standard users are the ones that are created during installation, while elevated users have some additional permissions. Elevated users usually have higher authority than regular users because of the extra privileges. Service users are a great example of elevated users.
How to Add or Create Users in Linux
Useradd is one of the most powerful commands provided in Linux. Keep in mind that only administrators can create new users on a system. Here’s the default syntax of the useradd command.
Useradd and adduser both have the same syntax and options. If you are on a distribution that uses adduser, just replacing the command name would suffice.
You can create a new user with the following command.
1. Creating User Passwords
When you add a new user, it is put in a locked state where no one can access it. To fix this, just assign a password to the newly created user. You can do this by using the passwd command.
After pressing Enter, type in the password that you want to assign to the user. Note that you won’t see it on your display, as this is the “Linux way” of protecting users from shoulder-surfing.
The “etc/passwd” file stores all the information related to user passwords. You can even check the file by typing nano /etc/passwd in your terminal.
2. Creating Users With Different Home Directories
When you create a new user on Linux, by default a new home directory is made for the user. By default, the directory name is the username of the new user. If you want your user to have a home directory with some other name, the -d flag is the one you need.
If you don’t want a user to have a home directory, you can use the -M flag.
3. Creating New User With a Custom UID
A UID or User ID is automatically assigned to new users. UIDs under 500 are reserved for administrators and super users. If you create your first regular user, the system will assign a UID of 501 to it.
To change this default behaviour, use the -u flag with the useradd command.
4. Adding a User to Groups
Linux provides you with a way to group your users into similar categories. For example, you can add all the administrators and superusers to the group name “admins”. Similarly the group “editors” can include all the video, image, or audio editors.
To add a user to a group, you can use the -G flag with the default command.
If you want to add a single user to multiple groups, just type in the group names separated by the comma character.
If you are running Ubuntu, note that adding and removing users from groups in Ubuntu is quite different from other distributions.
Creating Linux Users With GUI
If you are not comfortable with the Linux command line, don’t worry as most distributions allow you to add new users with a graphical user interface. While most of the time you will find user management options in the System Settings, different Linux desktop environments have their own ways to do the same.
On Ubuntu, open Settings > Details > Users > Unlock. Type in the root password if you already haven’t. You will find all the options you need related to user management. On systems running the KDE environment, go to System Settings and click on User Manager from the options.
Although the command line interface provides you with a variety of options that you can choose while creating new users, GUI stands out to be the best for beginners.
Managing Users on Linux
Adding new users is the most basic yet important thing that you should learn while managing a Linux machine. From personal computers to complex Linux-based servers, users form the base of a system.
A majority of people get confused when they first start using Linux on their computer. That’s why choosing the right distribution is important if you are switching from any other operating system to Linux.