How to Create User on Ubuntu Linux Command Line. In this post, we introduce the concept of user account, and its components. After that, we show you how to create a user on Ubuntu via the command line.
First of all, the user account is a security measure to ensure that only authorized users can access the system. Hence, a user account is also used to control the privileges of the user and track the usage of system resources. Linux administrators need to make sure that they have a secure password for their accounts and never share it with anyone.
To set up and use eDirectory to manage Linux access, you must understand how the user logins work.
So, the user must already have a user account with properties or authority to access files saved in a system, to log in to a Linux system. Local user accounts are those that are kept on the computer. Regardless of whether you have saved your account on the same computer or a different computer, accounts stored in eDirectory are referred to as eDirectory user accounts.
Usually, a Linux computer’s login account contains the following details:
Username and user ID (UID)
Both Username and UID are the two distinct identifiers that each user account has.
A user account’s username is mapped to a specific UID when it is created. Presently, a user can change the username as per his choice or requirement, but it must be unique. Remember the same username cannot be used by two users.
However, UID is fixed and unchangeable. Once an account is active, you cannot change the UID for that user account. Its role is to verify and keep track of user account activities and system resource usage.
The user uses their username, whilst the system uses their UID.
Password
You are already aware, that Passwords are a critical component of any security system. They provide the first line of defence against unauthorized access to your account. Each user account has a password that is encrypted and can be saved on the system itself. Then, it can be stored on a local password in the /etc/passwd or /etc/shadow file.
Remember, that Linux encrypts the password that the user enters when logging in and compares it with the saved password details. Significantly, the user is given access if the added value matches the one saved in the password field on the system.
For user account information, administrators choose /etc/passwd file, whereas the /etc/shadow file is for saving the encrypted passwords.
Primary group name and group ID (GID)
The Primary Group Name is the name of the group that a user belongs to. The Primary Group Name can be any string and does not need to be unique. A Primary Group ID must be unique for each group and it cannot contain spaces or special characters.
Secondary Group Names and ID’s
Secondary Groups are saved by administrators in /etc/group as entries and are not mandatory for user accounts. The Group ID is a unique number that identifies your group. Regardless, you use this ID to find and add members to the group.
Home Directory
Next component is a home directory. In effect, it is a directory in the file system that is assigned as the default location for a user’s data. The home directory is generally used to store personal files, like documents and pictures, but can also be used to store application data. Only the user and system administrator access this specific directory.
Preferred shell
The shell provides the user with a command line interface and a way to interact with the operating system. There are many different shells in use today, but the default shell for Linux is mostly /bin/bash.
We now came to the main part of the article How to Create User on Ubuntu Linux Command Line.
There are several ways to create a user on Ubuntu Linux. Create a user via the command line or through the GUI. In fact, creating users via the command line gives you more control and option compared to the graphical user interface. There are two command line tools you can use to create a user in Linux.
adduser – It is an interactive and friendly command line utility that allows you to create a user and set a password on the fly.
useradd – It is a low level utility. You will need to run another command to set a password after creating a user.
When you create a user using the useradd command, it will create a user’s home directory at /home/username location. You can also use define the custom home directory path using the -d option.
Let’s create a new user named testuser2 with a custom home directory path at /opt/.
useradd -m -d /opt/testuser2 testuser2
After creating a user, you can verify the user’s home directory using the following command:
The useradd command also allows you to create a user account with an expiration date. This is very helpful when you want to give someone temporary access to the system.
To create a user account named testuser4 and set an expiration date 2022-12-30, run the following command:
useradd -e 2022-12-30 testuser4
Next, you can now verify the user’s expiration date using the following command:
chage -l testuser4
You should see the user’s expiration date on the following screen:
How to Create User on Ubuntu Linux Command Line Conclusion
In this guide, we explained how to create users on UbuntuLinux via the command line. We show you how to use adduser and useradd commands to create a user account on Ubuntu. Also, we tried to explain each option you can use while creating a new user account on Ubuntu Linux. I hope this guide helps you to create a user account on Ubuntu Linux. Also there is a possibility to create a user account via the GUI interface but it has limited options.
Please take a look at more Ubuntu content by navigating to our blog over here.
I am a fan of open source technology and have more than 10 years of experience working with Linux and Open Source technologies. I am one of the Linux technical writers for Cloud Infrastructure Services.
00votes
Article Rating
Subscribe
Login and comment with
I allow to create an account
When you login first time using a Social Login button, we collect your account public profile information shared by Social Login provider, based on your privacy settings. We also get your email address to automatically create an account for you in our website. Once your account is created, you'll be logged-in to this account.
DisagreeAgree
Login and comment with
I allow to create an account
When you login first time using a Social Login button, we collect your account public profile information shared by Social Login provider, based on your privacy settings. We also get your email address to automatically create an account for you in our website. Once your account is created, you'll be logged-in to this account.