Ubuntu 24.04 introduces enhanced security and usability improvements, making user management an essential task for system administrators. Whether you’re setting up a multi-user environment or maintaining system security, understanding how to add and delete users efficiently is crucial.
This guide will walk you through the process of adding and removing users on Ubuntu 24.04 using both the command line and GUI methods.
Adding a User in Ubuntu 24.04
Method 1: Using the Command Line
The terminal provides a powerful and quick way to manage users.
1. Adding a New User
To add a new user, use the adduser
command, which is an interactive and user-friendly option:
sudo adduser <username>
Replace <username>
with the desired username. This command will prompt you to set a password and enter additional user details.
Alternatively, you can use the useradd
command, but it requires manual password setup:
sudo useradd -m -s /bin/bash <username>
sudo passwd <username>
Here:
-m
creates the user’s home directory.-s /bin/bash
sets Bash as the default shell.
2. Granting Administrative (sudo) Privileges
If the new user needs administrator rights, add them to the sudo
group:
sudo usermod -aG sudo <username>
Now, <username>
can run administrative commands using sudo
.
Method 2: Using the GUI
If you prefer a graphical approach:
- Open Settings.
- Navigate to Users.
- Click Unlock (enter your password if required).
- Click Add User.
- Enter the username, set a password, and select either Standard or Administrator privileges.
- Click Add to create the user.
Deleting a User in Ubuntu 24.04
Method 1: Using the Command Line
1. Removing a User Without Deleting Home Directory
Use:
sudo deluser <username>
This removes the user but keeps their home directory and personal files intact.
2. Removing a User and Deleting Home Directory
For a complete removal:
sudo deluser --remove-home <username>
This command deletes both the user and their home directory.
3. Removing a User and Their Files Completely
To remove all files owned by the user across the system:
sudo deluser --remove-home <username>
sudo rm -rf /var/mail/<username>
This ensures all remnants are removed.
Method 2: Using the GUI
- Open Settings > Users.
- Select the user you want to delete.
- Click Remove User and choose whether to keep or delete their home directory.
- Confirm the action.
Best Practices
- Always double-check usernames before deleting to prevent accidental data loss.
- Grant sudo privileges only to trusted users.
- Regularly audit and remove unnecessary user accounts to maintain security.
By following these steps, you can efficiently manage user accounts on Ubuntu 24.04, ensuring a secure and organized system.
FAQ
1. How do I check existing users on Ubuntu?
Run the following command to list all users:
cut -d: -f1 /etc/passwd
2. Can I change a user’s password?
Yes, use the command:
sudo passwd <username>
3. How do I remove a user from the sudo group?
Run:
sudo deluser <username> sudo
4. Can I disable a user without deleting their account?
Yes, you can lock the account using:
sudo passwd -l <username>
To unlock, use:
sudo passwd -u <username>
5. How do I add a user without a home directory?
Use:
sudo useradd -M <username>
- Roblox Force Trello - February 25, 2025
- 20 Best Unblocked Games in 2025 - February 25, 2025
- How to Use Java Records to Model Immutable Data - February 20, 2025