Adding users to a Linux computer is a basic management task, and there are several ways to achieve this. Each method has advantages and disadvantages. We explain three different techniques for you.
Computers Need User
A personal computer without a user is not really much. Linux supports more than one user. Whether they log in at the same time and share the power of the computer, or log in individually when using the machine exclusively, each person needs a unique user account.
A user account covers the work of that user and ensures confidentiality. It also allows you to control and manage your account. Different users may have different capabilities depending on their needs or role or function by changing the attributes of user accounts, for example, to which groups they belong.
Whether you share your computer with family members or manage multiple user setups for an organization, creating user accounts is a key administrative skill.
Since Linux is Linux, you have several ways to choose. We will go through three or two command line methods and one GUI based method so that you can choose the one that is most suitable for you.
useradd The command is the lowest level command used to add users. Acts as a friendly front for other commands
useradd command. This adds a little flexibility and simplifies the process, but other commands do nothing you can’t get.
useradd and help a little
useradd The command has many options, the ones needed to add a regular new user are listed 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
The order consists of the following:
- sudo: We need administrator privileges for a new user to access the computer.
- add user: The
- -s / bin / bash: Shell selection. This sets the default shell for this new user.
- -m: Option to create a home directory. This creates a directory with the same name as the new user account in the / home / directory.
- -c “Mary Quinn”: Full username of the new user. This is optional.
- -Gsambashare: Additional group selection. This is optional. A new username is added to the group with the same name. The
-Goption (note, large “G”) adds the user to additional groups. Groups should already exist. We also make the new user a member of the sambashare group.
- maryq: The name of the new user account. It must be unique. It can no longer be used for another user.
This creates a new user account, creates their home directory, and fills it with some standard hidden files. We can look at their home catalog as follows:
sudo ls -ahl /home/maryq
Our new user will not be able to log in. We did not create a password for them. It is possible to pass a password to
useradd command using
-p (password) option, but this is considered a bad experience. You must also enter a password encrypted is in shape, so it is not as simple as it seems.
easier and safer to use
passwd command to set a password for a new account.
sudo passwd maryq
You will be asked for a password, then you will be asked to enter it again to verify it. This password must be safely communicated to the new user. It is recommended that they be asked to change their passwords when logging in. This means that they can choose their passwords and no one else will know.
sudo passwd --expire maryq
By looking inside the / etc / passwd file, we can see our new user account and compare it to an existing account.
grep -E "dave|maryq" /etc/passwd
Areas separated by two dots “:” in sequence:
- maryq: User account name.
- x: The “x” in this field indicates that the user account 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 area. It can store the separated values of additional information with a comma “”. All we added was the full name of the user.
- / house / maryq: The path to the home directory for this account.
- / bin / bash: The path to the standard shell for this account.
When our new user logs in for the first time, they will use the password you created for them.
They will be asked to change their password as we set it to “expired”. They must log in again available password.
Then they are asked for a new password.
After they enter their new passwords and hit the “Enter” key, they are asked to re-enter the password to verify it.
Finally, they entered. They must then use a new password to log in.
Some homework is done, and the usual “Documents”, “Downloads” and other catalogs are created for them in the home directory.
The GECOS field can contain up to five commas. They are rarely used. If they are generally settled, he is usually the first to bear the real name of the owner of this account.
The areas are:
- This is the real name of the user.
- This is the user’s room number.
- Their work phone.
- Their home phone.
- Any other information.
If we wanted to provide all of these when creating an account, we could do the following:
sudo useradd -s /bin/bash -m -c "Mary Quinn,Operations 1,555-6325,555-5412,Team Leader" -Gsambashare maryq
we can use
grep to see if this information is stored in the / etc / passwd file.
grep maryq /etc/passwd
If you do not have this information when you create an account, it can be added or changed later
This information is used by commands as well
Additional user command
adduser The command includes creating an account, its home directory, setting a password, and entering GECOS field information into an interactive session.
adduser the team was already available on our Ubuntu and Fedora test machines, but had to be installed at Manjaro. It is in the Arch User Repository, so you should use an AUR assistant like you.
yay to install.
Use it to start the process
sudo and enter the name of the user account you added:
sudo adduser maryq
A standard group is created for the user account and the user account is added to that group by default. The home directory is created and hidden configuration files are copied to it.
You are asked to provide a password.
When you enter the password and hit the “Enter” button, you will be asked to re-enter the password to verify it.
You will be asked in turn for any information that may be included in the GECOS field.
Either give some information and press Enter to move to the next field, or just press Enter to move to the field.
Finally, you are asked if the information you provide is correct. Press the “Y” key and press the “Enter” key to complete the process.
Remember to set the password for the new account as “expired” so that the new user must change it the first time they log in.
sudo password --expire maryq
Open the system menu by right-clicking on the GNOME panel, next to the power, volume, and network icons.
Click on the “Settings” menu entry.
The settings program will open. Tap the “Users” entry in the sidebar, then click the “Unlock” button in the “Users” section.
You must enter your password.
The green “Add User” button will appear.
Click this button. The “Add User” dialog appears. It contains a form that captures the details of the new user.
Fill out the form with the details of the new user. If you want them to use
sudoClick the “Administrator” button.
You can either set their password now, or leave the password to them to choose the password when they first log in. If you set a password, you will need to open the terminal window and remember to use it.
passwd command it to be set to “expired”. This will force them to set their own passwords the first time they log in.
Going to the terminal is a bit of a pain when you try to use the GUI to create a new user.
If you click the “Allow user to set their password the next time you log in” radio button, a new password is required when the user tries to log in. But the downside here is that you are the first person to try to use a new account. can set a password. Thus, anyone who knows that an account has been created and defeats a real new user to log in can capture the account.
None of these situations are ideal.
After filling out the form and making your selections, click the green “Add” button.
We selected the option “Allow the user to set his password the next time he logs in”. A new password is required when the user tries to log in. However, unlike the sequence we saw earlier, they are not required to have a current password – they do not have a password.
As you would expect, they will have to re-enter it to check it out.
useradd The team gives granular control, but there is much to gain on the command line.
adduser The command simplifies life, but does not allow the new user to be added to additional groups.
The password radio button you choose for the GUI method has its drawbacks.
In most informal or domestic situations,
adduser The team probably gives the best balance between opportunity and functionality. If you need to add a new user to an additional group, you can do so after they are created
RELATED: Add a User to a Group (or Second Group) on Linux