In Linux, the administrator can create or add a user to the system to divide the task among other subordinate users. Administrators usually add regular users to the system to prevent them from accessing and messing up the base account. Adding multiple users on Ubuntu has many benefits, such as each user can customize the system according to their preferences and needs.
Administrators can create both regular and system users. A regular user only has administrator privileges or has access to the sudo command once you provide it. While, on the other hand, the system user is the one who has all administrator privileges and can modify critical system files and configurations.
Outline:
How to Add a User on Ubuntu 22.04
You can add user on Ubuntu 22.04 using:
How to Add a User on Ubuntu 22.04 Through Terminal
The new user can be added on Ubuntu through the:
Method 1: Add User on Ubuntu 22.04 Using the adduser Command
The adduser command creates a new user on the Linux system. It creates a home directory and configures the system for the new user side by side. Let’s check the instructions to add the user on Ubuntu 22.04.
Syntax:
Note: Remember to replace the [username] with the your desired username. For system users, add the “–system” flag.
Add a Regular User on Ubuntu 22.04
Type the below command and execute it to add a user on Ubuntu 22.04:
You will be asked to:
- Type the new user password and retype to confirm.
- Write your Full Name, Room Number, and Phone, or skip it by pressing the Enter button.
- Approve the information by entering Y.
Once the user is created, type the given command to verify whether the user was added successfully:
Add a System User on Ubuntu 22.04
Specify the username with the “–system” flag to add the system user on Ubuntu:
Verify the user creation by executing the given command:
Note: By default, the command used to add a system user doesn’t allow you to set the password for a specific system user. You have to manually set the password for the system user by using the below-given command:
Note: If you created a system user, you may face an issue accessing the terminal from the system user account. If you encounter such an error, you can manually set it by first log in to the administrator account, and then running the following command to enable shell access for the system user:
Replace the username with your username:
Method 2: Add User on Ubuntu 22.04 Using the Useradd Command
The useradd command can also be used to create a new user on Ubuntu 22.04. However, by default, the useradd command does not create a home directory and does not configure the newly created user configurations.
Syntax
Let’s start by understanding the syntax:
Where options include:
- -b: base directory
- -c: comment
- -r: system
- -p: password
- -N: no user group
- -s: shell
- -u: user id
- -h: help
Add Regular User on Ubuntu 22.04
Execute the useradd command with the username (without any options) to create a regular user:
Check whether the new user was created on Ubuntu by executing the id command followed by the username:
Set or Change the User Password on Ubuntu 22.04
For a user on Ubuntu, you can set or change the password using the below command:
After the command execution, type the new password and retype to confirm:
Add System User on Ubuntu 22.04
To add a system user using the useradd command, execute the given command:
Note: You can also use the -r option instead of the –system flag to add a system user in Ubuntu:
Verify the username using:
Create and Add a User to the Group
The useradd command allows you to create and add a specific user to the group using a single command:
The -G denotes the group, and we have assigned the group to it by the name of linuxways, followed by the username to be created:
Verify the user creation and addition to the group by executing the id command followed by the username:
Note: When adding a system user, you can not set the password for the specific user. However, you can set the system user password manually by executing the given command:
Method 3: Add User on Ubuntu 22.04 Using the newusers Command
The newusers command creates or updates the new users in bulk including regular and system users. The newusers command is mostly used in big IT companies where system administrators add a batch of users to the operating system. To add users in the batch using the newusers command, you have to create a text file first.
Syntax
Here is how to add the new user details in the text file:
Where,
- User_name: type the username you want to create
- Password: enter the username’s password
- User_ID: refers to the user ID to be created in the system
- Group_ID: refer to the group ID in the system
- User_Info: user information such as full name
- Home_Directory: refers to the user’s home directory
- Default_Shell: refers to the default shell
Check the stepwise guide below to add multiple regular users on the Ubuntu system through the newusers command.
Step 1: Create a File and Add the Users Data
To create a batch of regular users, first, we need to create a text file to add the users to it using the nano text editor in the Terminal. For that, run the given command:
Let’s add six users including their details in the text file. A new line must separate each user detail:
linuxways2:pswd@123:1002:1002::/home/linuxways2:/bin/sh
linuxways3:pswd@123:1003:1002::/home/linuxways3:/bin/sh
linuxways4:pswd@123:1004:1004::/home/linuxways4:/bin/sh
linuxways5:pswd@123:1005:1005::/home/linuxways5:/bin/sh
linuxways6:pswd@123:1006:1006::/home/linuxways6:/bin/sh
Save the data and exit the file.
Step 2: Add Users to the Ubuntu System
Provide that “.txt” file to the newusers command (as an argument), as shown below:
Step 3: Verify the Batch User’s Creation
Check the user addition on Ubuntu by fetching the users from user ID 3 to 1000 by executing the below command:
Note: Adding multiple system users to the Ubuntu system is no different than adding the regular users except for adding the –system flag. The system user details are the same as the regular user except for adding a false value in the default shell environment and keeping the user ID range from 100-999.
How to Add User on Ubuntu 22.04 Using GUI (Graphical User Interface)
Just like CLI, a user can also be added to Ubuntu 22.04 using GUI settings. The steps to add a user on Ubuntu 22.04 using GUI are below.
Step 1: Open System Settings
Hit the panel in the top-right corner and select Settings:
Step 2: Open Users Settings
Navigate to the Users tab, and click on the Unlock button to configure users:
Enter the password to authenticate for user configuration:
Step 3: Add User on Ubuntu
Click on the Add User button to create a new user account:
Provide the user details such as account type, name, or password, and click the Add button to create the user account:
Note: To create the Administrator user, select the Administrator option.
Type the password and hit Authenticate to allow Ubuntu to add the user:
Step 4: Verify the User Addition
Open system Settings, navigate to the Users tab, and there you can see the newly added user on Ubuntu:
How to Add a User to a Sudo Group on Ubuntu 22.04
By default, every new user is created as the standard user in Ubuntu. To make it the administrator or sudo user, we need to execute a command manually.
Syntax
Remember: Replace the [Username] with your desired username.
Execute this code in the Terminal to add the user to the sudo group:
Execute the groups command along with the username to check the user addition in a sudo group:
How to Remove a User on Ubuntu 22.04
The methods to remove a user on Ubuntu 22.04 are the same as for adding a user, such as using CLI and GUI.
Method 1: Remove User on Ubuntu 22.04 Using Terminal
Open Terminal and execute the below command to delete the user from Ubuntu:
Note: Replace johnny with the username you want to delete.
Verify the user deletion by executing this command:
Note: Replace the johnny username with the username you want to delete:
The output shows that the user no longer exists.
Method 2: Remove User on Ubuntu 22.04 Using GUI
To remove a user from Ubuntu, open Settings, move to the Users tab, unlock the users, and click the Remove User button:
Select Delete Files to remove all files:
Enter the user password and click the Authenticate button to remove the user from Ubuntu:
Conclusion
Ubuntu lets you add users to the system, so you as a family can use a single machine individually with full privacy. Administrators can add a user on Ubuntu through Terminal and GUI. To add a user on Ubuntu using Terminal, users can use the useradd, newusers, and adduser commands. Moreover, to add a user using GUI, open Settings > Users, authenticate the system to configure users, hit the Add User button, add user details, and click the Add button.