How to Create a User in Linux

Creating users is one of the most fundamental tasks in Linux. System admins have to constantly manage users as the company’s size grows or shrinks. Or maybe you want to add a user in Linux to allow one of your family members to use your computer and prevent them from accessing your personal data. Whatever the case may be, in this guide, let’s look at how to create a user in Linux. There are two ways to create a new Linux user and we have explained both using examples.

Create a User in Linux using useradd Command

Creating a new Linux user using the useradd command is the oldest method. Before we get started with the same, you can first list all Linux users to check if the user you’re trying to add already exists. There are four ways to list users but the most common command is the following one.

getent /etc/passwd
getent-passwd-command

If you don’t see the user here, you can proceed to add them using useradd command. Here is the syntax for the useradd command:

sudo useradd -s /bin/bash -m -c "Full Name" -G"nameofthegroub" "username"

Let us explain the use of each entity in the above command one by one.

  • Sudo: Creating a new user requires superuser privileges.
  • useradd: The useradd command is used to tell Linux that we want to add a new user.
  • -s: is used to set the default shell
  • -m: Adds and assigns a /home directory to the user.
  • -c: Takes the full name of the user.
  • -G: Assigns the user to a group. This group can then be used to add more users.
  • tayeeb: is the name of the user account.

An example of the useradd command would look like the command below.

sudo useradd -s /bin/bash -m -c "Tayeeb Hasan" tayeeb
Created user Tayeeb

Now that the account has been created, it’s still not protected as there is no password. There are two ways to set a password. First, you can do it yourself if you’re an admin and then tell the password to the profile holder. Alternatively, the best way to do the same is by setting a temporary password for the newly created user and letting the user choose what password they want to set later. This can be done using the following command. Once you execute this command, enter a temporary password.

sudo passwd --expire "username"

Swap the username with an actual username and it should look like this:

sudo passwd --expire tayeeb
adduser tayeeb and expire password

This way, you can set an initial password for the user and give it to them after which Linux will then ask them to enter a new password twice, which will then be the new password.

Create a User in Linux using adduser Command

The adduser command was added much later in the kernel and it makes adding users a piece of cake and swift. Now, you must be confused between the useradd command and adduser command due to the same name. However, there are a couple of differences between the two Linux commands.

useradd is a built-in Linux command, whereas adduser is a high-level utility command that offers plenty of customization options while creating a user in Linux. Using adduser command, you can create a home directory for new users, set a password, and there are several parameters that you can use with this command.

Here’s how to add a user in Linux using the adduser.

sudo adduser "username"
adduser command ubuntu

The command will then prompt you to enter your password, the name of the user, and other details, before asking for the password twice. Once done, you can use the command passwd --expired to let the user change their password the next time they try logging in via the new account. For us, adduser worked well on a Ubuntu VM but not on Fedora for an unknown reason.

New password for Tayeeb hasan

Once executed, the command asks you to enter and confirm a password and enter the full name of the user. You can skip the remaining fields if you want such as the phone number, room number, etc.

entering the details for new user in Linux terminal

Create a User in Linux using GUI

The process of creating a new user on Linux is as simple as on Windows. Here’s how to create a new user on Linux using GUI.

1. Go to Settings > Users and unlock the menu using your password.

Settings and Users in Linux GUI

2. Click Add User button from the other Users section.

Add user button in Linux GUI

3. Enter the name, username, password, and other details of the new Linux user.

Users menu in Settings in Linux GUI

3. Finally, click Add and the new user should now appear when the current user logs out.

4. If you want to allow the user to set their own password during the next login, go to user details > Password and check the “Allow user to change their password.”

allow user to change the password
comment Comments 0
Leave a Reply