en How to create a user on Linux

How to create a user on Linux

Creating a user is one of the most basic tasks in Linux. System administrators must constantly manage users as their company grows or shrinks. Or maybe you want to add a user to Linux to allow a family member to use your computer but not have access to your personal data. In any case, in this guide, let’s take a look at how to create a user on Linux. There are two ways to create a new Linux user, and both methods have been explained using examples.

How to create a user on Linux
How to create a user on Linux

Create a user on Linux using the useradd command

The oldest method is to create a new Linux user using the useradd command. Before starting the same, first list all Linux users and check if the user you are trying to add already exists. There are four ways to list users, but the most common command is:

 getent /etc/passwd

If you don’t see your user here, you can proceed to add the user using the useradd command. The syntax of the useradd command is:

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

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

  • Sudo : Requires superuser privileges to create new users.
  • useradd : The useradd command is used to tell Linux to add a new user.
  • -s : used to set the default shell
  • -m : Adds the /home directory and assigns it to the user.
  • -c : Get the user’s full name.
  • -G : Assign users to groups. You can add more users using this group.
  • tayeeb : The name of the user account.

An example useradd command might look like the following command:

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

Your account has been created, but it’s not yet secured because you don’t have a password. There are two ways to set a password. First, if you’re an administrator, you can set a password yourself and give the password to the profile owner. Alternatively, the best way to do the same thing is to set a temporary password for the newly created user and let the user choose a password to set later. This can be done using the following command: After you run this command, enter your temporary password.

 sudo passwd --expire "username"

If you replace the username with your actual username, it will look like this:

 sudo passwd --expire tayeeb

This way, when you set an initial password for a user and give it to the user, Linux will prompt the user to enter the new password twice. This will be your new password.

How to create a user on Linux
How to create a user on Linux

Create a user on Linux using the adduser command

The adduser command was added much later in the kernel to make adding users easier and faster. Here you should confuse the useradd and adduser commands because they have the same name. However, there are some differences between the two Linux commands.

useradd is a built-in Linux command, while adduser is a high-level utility command that provides many customization options when creating users on Linux. You can use the adduser command to create a new user’s home directory and set a password. Additionally, there are several parameters you can use with this command.

Here’s how to add a user using adduser on Linux:

 sudo adduser "username"

This command prompts you for your password, username, and other details before prompting you for your password twice. Once done, use the command passwd --expired to allow the user to change their password the next time they log in with a new account. In our case, adduser worked fine on Ubuntu VM, but on Fedora for unknown reasons.

When you run the command, you will be asked to enter and confirm your password and to enter your full name. You can skip the remaining fields like phone number, room number, etc. if you wish.

How to create a user on Linux
How to create a user on Linux

Create a user on Linux using the GUI

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

1. Go to Settings > User and use your password to unlock the menu.

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

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

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

4. To allow users to set their own passwords the next time they log in, go to User Details > Passwords and check “Allow users to change their passwords.”

How to create a user on Linux
How to create a user on Linux