Skip to content

  • Technology
  • Humanities
  • Sports
  • Lifestyle
  • Toggle search form

How to add users to Linux

Posted on June 20, 2022 By admin No Comments on How to add users to Linux

fatmawati achmad zaenuri / Shutterstock.com

Adding a user to a Linux computer is a basic administration task, and there are several ways to achieve this. Each method has advantages and disadvantages. We explain three different techniques.

Computers need users

A personal computer without a user is not much. Linux supports multiple users. Whether logging in and sharing computer power at the same time, or logging in individually when they have exclusive machine use, each person needs a unique user account.

The user account covers the work of that user and provides privacy. It also allows the application of control and management to the account. Different users may have different options according to their needs or their role or function by changing the attributes of their account, such as which group they belong to.

Whether you share your computer with family members or administer a multi-user installation for an organization, creating user accounts is a basic administrative skill.

Since Linux is Linux, you can choose from several methods. We’ll walk you through three – two command line methods and one GUI-based method – so you can choose the one you think works best for you.

Command useradd

The useradd command is the lowest level command used to add users. Other commands act as friendlier front-ends for useradd team. This adds some convenience and makes the process easier, but other commands don’t do anything you can’t accomplish with useradd and a little help from passwd team.

The useradd the command has many options, the ones you will need to add a typical new user are shown below. Needless to say, you will have to use it sudo to add a user.

sudo useradd -s /bin/bash -m -c "Mary Quinn" -Gsambashare maryq

Adding a typical user with useradd

The command consists of:

  • sudo: We need administrator privileges to allow a new user to access the computer.
  • useradd: The useradd team.
  • -s / bin / bash: Shell option. This sets the default shell for this new user.
  • -m: Make a home directory option. This creates a directory in the “/ home /” directory with the same name as the new account name.
  • -c “Mary Quinn”: Full name of the new user. This is optional.
  • -Gsambashare: Additional group option. This is optional. A new user is added to the group with the same name as his account name. The -G option (note, capital “G”) adds the user to additional groups. Groups must already exist. We are also making a new user a member of the “sambashare” group.
  • maryq: Name of the new user account. This must be unique. Cannot be used for another user.

This creates a new user account, creates their home directory and populates it with some default hidden files. We can look at their home directory like this:

sudo ls -ahl /home/maryq

Default configuration files added to the new user's home directory

Our new user will not be able to log in. We did not create a password for them. It is possible to transfer the password to useradd command using your -p (password), but this is considered bad practice. Moreover, you must enter the password in your encrypted shape, so it’s not as simple as it sounds.

It is easier and safer to use passwd command to set a password for a new account.

sudo passwd maryq

Set a password for a new account

You are asked for a password, and then you are asked to enter it again to confirm it. This password must be securely passed on to the new user. It is recommended that they be asked to change their password when logging in. This means that I can choose my own password and no one else will know it.

sudo passwd --expire maryq

Set a new user password to an expired state

We can see our new account and compare it with the existing one by looking inside the “/ etc / passwd” file.

grep -E "dave|maryq" /etc/passwd

Comparison of / etc / passwd entries of a new user account and another account

Separately, the colon “:” separate fields are:

  • maryq: The name of the user account.
  • x: “X” in this field means that the user password is encrypted and stored in the “/ etc / shadow” file.
  • 1001: User account ID.
  • 1001: The default group ID for this user account.
  • Mary Quinn: This is the GECOS field. May contain a set of values ​​of additional information separated by commas, “. All we’ve added is the full username.
  • / home / maryq: The path to the home directory for this account.
  • / bin / bash: The path to the default shell for this account.

When our new user first logs in, they will use the password you created for them.

A new user is logging in

Since we have set their password to “expired”, they will be asked to change it. They have to get back into their own existing password.

Re-enter the current user password as the first part of the password change

They are then asked for a new password.

Enter a new password

When they type their new password and press “Enter”, they are asked to re-enter the password to confirm it.

Checking new password

Finally, they are reported. From now on, they must use a new login password.

Certain maintenance is performed and the usual “Documents”, “Downloads” and other directories in their home directory are created for them.

Default directories created within the user's home directory

The GECOS field can contain up to five information separated by commas. These are rarely used. If some are filled in at all, it is usually the first, which contains the real name of the owner of this account.

The fields are:

  • Real name of this user.
  • This user’s room number.
  • Their work phone.
  • Their home phone.
  • Any other information.

If we wanted to provide all this when we created the account, we could have done it like this:

sudo useradd -s /bin/bash -m -c "Mary Quinn,Operations 1,555-6325,555-5412,Team Leader" -Gsambashare maryq

Add a new user with a filled GECOS field, using useradd

We can use grep to see that this information is stored in the “/ etc / passwd” file.

grep maryq /etc/passwd

Looking at the entry in / etc / passwd for the new user, with grep

If you do not have this information at hand when creating an account, you can add or change it later using chfn team.

This information is used by commands such as finger i pinky.

finger maryq

Use a finger command on a new user

Adduser command

The adduser the command includes creating an account, its home directory, setting a password and capturing GECOS field information in one interactive session.

The adduser the command was already present on our Ubuntu and Fedora test machines, but had to be installed on Manjaro. It is located in the Arch User Repository, so you will need to use an AUR assistant such as yay to install it.

yay adduser

Use yay on Manjaro to install the adduser

Use to start the process sudo and specify the account name you are adding:

sudo adduser maryq

A default account group has been created, and an account is added with that group as the default. The home directory is created and the hidden configuration files are copied to it.

You are prompted to enter a password.

Use an adduser to add a new user

When you enter the password and press “Enter”, you will be asked to re-enter the password to confirm it.

You are asked for each of the information that can enter the GECOS field.

Set a password for a new account using adduser

Either give some information and press “Enter” to move to the next field, or simply press “Enter” to skip the field.

Completed GECOS information in the adduser command

In the end, you wonder if the information you provided is accurate. Press “Y” and press “Enter” to complete the process.

Don’t forget to set the password for the new account as “expired” so that the new user is obliged to change it when they log in for the first time.

sudo password --expire maryq

Set a new user password to an expired state

GUI method

Open the system menu by clicking on the right edge of the GNOME panel, near the power, volume, and network icons.

GNOME system menu

Click on the “Settings” menu item.

The Settings application opens. Click the “Users” entry in the sidebar, then click the “Unlock” button in the “Users” pane.

The Users pane in the Settings application

You will need to enter your password.

Authentication in the Settings application

The green “Add user” button will appear.

The Users pane in the Settings app is unlocked

Click this button. The Add User dialog box appears. Contains a form that records details about the new user.

Add user dialog

Fill out the new user information form. If you want you can use them sudoclick the “Administrator” button.

You can set their password now or let them choose a password when they first log in. If you set a password, you will need to remember to open the terminal window and use passwd command to set it to the “expired” state. This will make them set their own password when they first log in.

It’s a little difficult to go to the terminal when trying to use the GUI to create a new user.

If you click the “Allow user to set their own password the next time they log in” radio button, the user will be prompted to enter a new password when they try to log in. But the downside is that the first person to try to use a new account can set a password. So, anyone who knows that the account has been created and who wins the right new user to try to log in, can download the account.

None of these situations are ideal.

Click the green “Add” button when you fill out the form and make your selections.

We have selected the “Allow user to set their own password the next time they log in” option. When a user tries to log in, they are asked for a new password. But, unlike the sequence we saw earlier, they are not asked for the current password – they do not have it.

The new user is forced to choose a new password

As you would expect, they have to enter it once more to confirm it.

Checking new password

Decisions Decisions

The useradd command gives detailed control, but there is much that can be achieved on the command line.

The adduser the command makes life easier, but does not allow you to add a new user to additional groups.

The GUI method has the disadvantages of whichever radio button you choose.

In most informal or home situations, adduser the command probably gives you the best balance between features and functionality. If you need to add a new user to an additional group, you can do so after they have been created, using usermod team.

RELATED: Add a user to a group (or other group) on Linux

Technology

Post navigation

Previous Post: No, Ukraine does not suffer 1,000 victims every day
Next Post: The new weight loss treatment Plenity gets huge marketing. How well does it work?

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Archives

  • July 2022
  • June 2022
  • May 2022

Categories

  • Humanities
  • Lifestyle
  • Sports
  • Technology
  • Travel

Recent Posts

  • Dear streamers, stop making TV shows that shouldn’t be full shows
  • The Profound Climate Implications of the Supreme Court’s West Virginia v. EPA Decision
  • The following revolutionary iPhone features may depend on these technologies
  • Giant thermoses and waste water on tap
  • 7 Stress Relief Strategies That Really Work

Recent Comments

No comments to show.
  • About us
  • DMCA
  • Privacy Polic
  • Terms and conditions

Copyright © 2022 .

Powered by PressBook WordPress theme