How To Add Users in Ubuntu 24.04 LTS

add users in Ubuntu 24.04

Adding users is a fundamental responsibility of system administrators, crucial for maintaining secure access and efficient resource allocation. Regular users need accounts for their daily operations, and administrators require robust ways to manage these accounts seamlessly. Effective user addition ensures that each user has the appropriate access and permissions for their role.

Also, read How to delete users in Ubuntu 24.04 LTS.

How To Add Users in Ubuntu 24.04 LTS

Ubuntu 24.04 LTS offers diverse methods for adding users, accommodating various preferences and needs. Whether you prefer the precision of terminal commands, the convenience of a graphical interface, or the efficiency of automation scripts, this guide covers it all. In this comprehensive guide, we will explore multiple methods for adding users in Ubuntu 24.04 LTS, including:

  • Using the Command Line: Employing powerful commands like adduser and useradd for detailed and controlled user creation.
  • Using the Graphical User Interface (GUI): Managing user accounts through Ubuntu’s intuitive settings interface.
  • Adding Users Temporarily: Creating users with expiration dates for specific tasks.
  • Automating User Creation with Scripts: Streamlining bulk user creation with custom scripts.

Each method is detailed with step-by-step instructions to ensure you can add users effectively and effortlessly, enhancing your Ubuntu experience.

Method 1: Adding a User Using the Command Line

This method is ideal for administrators who prefer using terminal commands.

Using adduser

An easy-to-use, high-level command for adding users is the adduser. It provides a guided process to set up a new user, including setting a password and additional user information.

Step 1: Open the Terminal

To access the terminal, simultaneously depress the Ctrl, Alt, and T keys. Alternatively, search for “Terminal” in your application menu.

Step 2: Add a New User

Execute the following command:

sudo adduser newuser

Substitute newuser with your desired username.

The password must be entered when prompted.

Take Note:

Make sure the password satisfies the following requirements:

  1. Minimum of 8 characters.
  2. Includes both upper and lower case letters.
  3. Contains at least one number.
  4. Includes special characters (e.g., !, @, #, $, etc.).

Enter the password and press Enter.

Type the password one more time and hit Enter to confirm it.

Some details will be asked while adding a new user like full name, room number, work phone, and home phone.

Any field can be skipped by pressing Enter.

After entering the information, you will see a summary of the details.

Confirm the details by typing Y and pressing Enter.

Step 3: Verify User Creation

Execute the below-given command to check the new user’s addition:

getent passwd newuser

If the command is successful in creating the user, the user’s details will be shown like this:

Using useradd

A low-level utility for creating new users is the useradd command. It requires more specific options but offers greater control over the user creation process.

Step 1: Open the Terminal

The terminal can be opened by simultaneously holding down the Ctrl, Alt, and T keys.

Step 2: Add a New User

Run the following command, and substitute new_username with the username you prefer:

sudo useradd -m new_username

Making sure the user’s home directory is created is ensured by the -m option.

Step 3: Set Password for the User

The new user can be assigned a password by using:

sudo passwd new_username

Type the password one more time and hit Enter to confirm it.

Step 4: Verify User Creation

Execute the below-given command to check the new user’s addition:

getent passwd new_username

If the command is successful in creating the user, the user’s details will be shown.

Additional Steps (Optional)

Adding the User to a Specific Group

Use the below-given command to add a new user to a certain group:

sudo usermod -aG groupname newuser

Replace groupname with the desired group (e.g., sudo, admin, docker).

Execute the below-given command to check the new user’s addition:

groups new_username

This command will list all the groups that the user belongs to, including the new group.

Method 2: Adding a User Using GUI (Graphical User Interface)

For those who prefer a graphical interface, Ubuntu provides an easy way to manage users through its settings. Here’s a step-by-step guide to adding a new user using the GUI.

Step 1: Open Settings

To access the terminal:

Search for “Settings” in your application menu.

Step 2: Access Users Section

In the Settings window, go to the search bar at the top and type “Users.”

As an alternative, move to the sidebar’s bottom and select “System.”

Click on “Users” from the options available in the System settings.

Step 3: Unlock User Management

Select the “Unlock” button by moving to the upper right corner.

Enter your administrative password and click “Authenticate.”

Step 4: Add New User

Click the “Add User” button.

Input the required data, including your username and name.

You can choose to keep the toggle button inactive by default to designate the new user as a “Standard” user.

Then insert password.

Step 5: Confirm and Apply

Click “Add” to create the user.

Now the new user will appear in the user list.

Take Note

User Management:

Once the user is created, click on the username in the Users section to manage its settings.

Method 3: Adding a User Temporarily

For certain tasks, you might need to add a user that expires after a specified period. This method outlines how to create a user with an expiration date using the command line.

Step 1: Open the Terminal

The terminal can be opened by simultaneously holding down the Ctrl, Alt, and T keys.

Step 2: Add a User with an Expiry Date

Execute the following command:

sudo useradd -m -e YYYY-MM-DD temporaryuser

Replace YYYY-MM-DD with the desired expiration date and temporaryuser with your desired username.

Step 3: Set Password for the User

The new user can be assigned a password by using:

sudo passwd temporaryuser

Enter the password, when prompted.

Type the password and press Enter.

Type the password one more time and hit Enter to confirm it.

Step 4: Verify User

To verify that a temporary user has been created successfully, use the below-given command:

sudo chage -l temporaryUser

Substitute the temporaryuser with the username you want to verify.

Method 4: Automating User Creation with Scripts

The method outlined here demonstrates automating user creation with scripts, particularly useful for bulk user creation tasks.

Step 1: Open the Terminal

The terminal can be opened by simultaneously holding down the Ctrl, Alt, and T keys.

Step 2: Create a Script

Any text editor will work for writing the script. Using nano, for instance:

nano add_users.sh

Step 3: Add Script Content

Add the following content to the script. Modify the usernames and other details as needed.

#!/bin/bash

sudo adduser user1 --gecos "First Last,RoomNumber,WorkPhone,HomePhone" --disabled-password

echo "user1:password1" | sudo chpasswd

sudo adduser user2 --gecos "First Last,RoomNumber,WorkPhone,HomePhone" --disabled-password

echo "user2:password2" | sudo chpasswd

Replace user1, user2, etc., with the desired usernames.

Modify the –gecos option to provide additional information about the user (optional).

Replace the password with the desired password.

Adjust the script content as needed, adding more users or customizing user details.

Save and close the file.

Step 4: Make the Script Executable

To enable the script to run, use the chmod command.

chmod +x add_users.sh

Step 5: Run the Script

Run the script to create the users.

./add_users.sh

Conclusion

User management in Ubuntu 24.04 LTS is a critical task for system administrators, providing security, efficient resource allocation, and smooth system operation. With various methods available, from command-line interfaces to graphical user interfaces and automation scripts, Ubuntu 24.04 LTS ensures that adding users can be tailored to different needs and preferences. By following the comprehensive steps outlined in this guide, you can effectively manage regular users.