Manage Users in Ubuntu 24.04

Manage Users in Ubuntu 24.04

Introduction

Managing users on an Ubuntu system is a critical task for ensuring system security and smooth operations. Whether you’re adding new users, assigning sudo privileges, or removing accounts, these actions are essential for maintaining control over who has access to your system. In Ubuntu 24.04, it’s crucial to manage user permissions effectively to prevent unauthorized access and safeguard sensitive data. This guide walks you through the necessary steps for adding, modifying, and deleting users on Ubuntu, along with tips for locking accounts and recovering deleted files.

What is User management on Ubuntu 24.04?

This solution involves adding, removing, and managing users on an Ubuntu 24.04 system. It helps system administrators create user accounts, assign permissions, grant administrative privileges using sudo, and handle user deletion or account locking. The goal is to maintain security and control by giving users appropriate access while preventing unauthorized actions.

1: Adding a User

Imagine you’re the admin of a busy Ubuntu system, and you need to create a new user. If you’re logged in as the root user, you’re the one in charge and can create a new user anytime you need. Just type this command:

$ adduser newuser

But if you’re a regular user with sudo privileges, no worries! You can still add a user, but you’ll need to use sudo to boost your permissions:

$ sudo adduser newuser

After you hit enter, you’ll be greeted with a friendly set of prompts. First, you’ll pick a password for the new user and confirm it. Next, you’ll be asked to fill in some optional details like the user’s full name, room number, and contact info. But don’t stress about it—if you don’t feel like entering this info, just hit ENTER to skip. Finally, you’ll see a summary of the info you’ve provided, and all you have to do is confirm with a “Y.” Once that’s done, the new user account is ready! They can now log in using the password you created. If you want them to have some extra power—like the ability to make system-wide changes—keep reading for the next step!

2: Granting a User Sudo Privileges

Now that your new user is all set up, it’s time to give them some extra powers. You’ll need to grant them the ability to run commands with root privileges, like installing software or changing important system settings. There are two ways to do this.

Adding the New User to the Sudo Group

By default, any user in the “sudo” group can run commands as the root user. It’s the easiest way to get things rolling. If you want to check which groups your new user belongs to, just type this:

$ groups newuser

The result will look something like this:

Output
newuser : newuser

That means the new user is only in their own group for now. Now, let’s add them to the sudo group. To do this, you’ll use the usermod command:

$ usermod -aG sudo newuser

The -aG option tells the system to add the user to the sudo group. Just keep in mind, to run this command, you’ll need sudo privileges yourself. So if you’re not the root user, you’ll need to use sudo as well:

$ sudo usermod -aG sudo newuser

Specifying Explicit User Privileges in /etc/sudoers

If you want to have a bit more control over what each user can do, you can directly edit the /etc/sudoers file. This is a great option if you want to be more specific about what actions the new user can perform. To do this safely, you’ll use the visudo command, which opens the /etc/sudoers file. It’s the best way to avoid mistakes that could lock you out of sudo privileges. Here’s how you open the file:

$ visudo

If you’re logged in as a non-root user with sudo privileges, you’ll need to prefix the command with sudo:

$ sudo visudo

Once the file is open, use the arrow keys to search for the line that looks like this:

Output
/etc/sudoers root ALL=(ALL:ALL) ALL

Under that line, add the following line to give your new user full sudo privileges:

Output
/etc/sudoers root ALL=(ALL:ALL) ALL newuser ALL=(ALL:ALL) ALL

This grants the new user full access to run all commands as root. When you’re finished, save and exit by pressing CTRL + X, followed by Y to confirm, and then ENTER.

3: Testing Your User’s Sudo Privileges

Once you’ve given the new user sudo privileges, it’s time to test things out. When logged in as the new user, you can run commands as usual, like so:

$ some_command

But when you need to run something that requires root access, just add sudo at the start of the command:

$ sudo some_command

The system will ask the new user to type in their password. If everything’s set up correctly, the command will run with elevated privileges, confirming that sudo is working as it should.

4: Deleting a User

There will come a time when you need to delete a user who is no longer needed. You can do this without touching their files by running this command as the root user:

$ deluser newuser

If you’re a non-root user with sudo privileges, just add sudo at the start:

$ sudo deluser newuser

If you want to go a step further and remove the user’s home directory along with the account, use the --remove-home option:

$ deluser –remove-home newuser

For non-root users with sudo privileges, it would look like this:

$ sudo deluser –remove-home newuser

If you granted the user sudo privileges earlier, it’s a good idea to remove their entry from the /etc/sudoers file to avoid any issues later. Use visudo to edit it:

$ sudo visudo

Find the line where you added the user and delete it:

Output
/etc/sudoers root ALL=(ALL:ALL) ALL newuser ALL=(ALL:ALL) ALL

Lastly, if the user was part of a group and no one else is in that group, you can remove the group with:

$ sudo delgroup groupname

5: Locking a User Instead of Deleting

Sometimes you might not want to delete a user permanently, but just lock them out for a bit. This is useful if you need to temporarily disable a user account without messing with their files.

Locking the Password

A simple way to lock a user account is by disabling their password. This means they won’t be able to log in. To do this as the root user, run:

$ passwd -l username

If you’re a non-root user with sudo privileges, use:

$ sudo passwd -l username

This command locks the user’s password by adding a ! or * character to it in the /etc/shadow file. If you ever want to unlock the password and let the user log in again, just run:

$ passwd -u username

For non-root users with sudo privileges, prefix the command with sudo:

$ sudo passwd -u username

Disabling the Account (No Login Shell)

Another way to lock a user is by changing their login shell to a non-existent one. This stops them from starting an interactive session, effectively locking them out. To change their shell to /usr/sbin/nologin, run:

$ sudo usermod -s /usr/sbin/nologin username

If you want to change their shell back to the original (like /bin/bash), just run:

$ sudo usermod -s /bin/bash username

6: FAQs

1. What is the difference between adduser and useradd? adduser is a simple, user-friendly script that makes creating a new user easy. It prompts you for the necessary details, automatically creates a home directory, copies over default files (like .bashrc and .profile), sets permissions, and assigns a shell. It’s the go-to command for most Debian-based systems like Ubuntu. On the other hand, useradd is a more basic command that lets you control the user creation process more precisely. It doesn’t automatically create a home directory or copy skeleton files—you have to do that yourself. It’s often used in scripts or for automating system tasks where you need fine-tuned control.

2. How do I give a user sudo privileges in Ubuntu? The easiest way to give a user sudo privileges is by adding them to the sudo group. Members of this group can run commands with root privileges. To add a user to the sudo group, run:

$ sudo usermod -aG sudo username

Just replace username with the actual name of the user. These changes will take effect the next time the user logs in.

3. Does deleting a user also remove their files? When you delete a user with the deluser command, their account is removed, but their home directory and files stay intact. If you want to delete the user’s home directory and files as well, use the --remove-home option:

$ sudo deluser –remove-home username

You can also back up the user’s home directory before deleting it by using the --backup-home option.

4. Can I recover a deleted user? Recovering a deleted user account isn’t straightforward. Once you delete a user, their entry is removed from system files like /etc/passwd, /etc/shadow, and /etc/group. But if you deleted the account without removing their home directory, the user’s files may still be on the system. You can recreate the user with the same username and UID/GID, then point the new home directory to the old one to restore access to their files.

For more details on creating a sudo user on Ubuntu, check out this tutorial.

Conclusion

In conclusion, managing user accounts on Ubuntu 24.04 is an essential skill for maintaining system security and ensuring proper access control. Whether you’re adding users, granting them sudo privileges, or safely deleting accounts, understanding these tasks is crucial for a well-functioning Ubuntu system. By following best practices for user management, you can secure sensitive data and manage access effectively. As Ubuntu continues to evolve, staying updated with new user management features and security practices will help you maintain a safe and efficient environment. Keep these techniques in mind to ensure smooth user administration on your Ubuntu system.For seamless user management, mastering these skills is key to maintaining the security and integrity of your Ubuntu system.

Run Python Scripts on Ubuntu: Master Virtual Environments and Execution (2025)

Alireza Pourmahdavi

I’m Alireza Pourmahdavi, a founder, CEO, and builder with a background that combines deep technical expertise with practical business leadership. I’ve launched and scaled companies like Caasify and AutoVM, focusing on cloud services, automation, and hosting infrastructure. I hold VMware certifications, including VCAP-DCV and VMware NSX. My work involves constructing multi-tenant cloud platforms on VMware, optimizing network virtualization through NSX, and integrating these systems into platforms using custom APIs and automation tools. I’m also skilled in Linux system administration, infrastructure security, and performance tuning. On the business side, I lead financial planning, strategy, budgeting, and team leadership while also driving marketing efforts, from positioning and go-to-market planning to customer acquisition and B2B growth.

Any Cloud Solution, Anywhere!

From small business to enterprise, we’ve got you covered!

Caasify
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.