add user

How To Add and Delete Users on Ubuntu 24.04 and CentOS 8

Managing users on a Linux system is an essential skill for system administrators and users alike. Whether you need to create a new account for a colleague or remove a user who has left the organization, understanding how to manage users efficiently is key for maintaining a secure and organized system. In this blog post, we’ll cover the steps to add and delete users on two popular Linux distributions: Ubuntu 24.04 and CentOS 8.

Prerequisites

Before we dive into the specifics of user management, ensure you have:

  1. Access to a terminal with root or sudo privileges on your server.
  2. Familiarity with basic Linux commands.

Adding Users

Adding Users on Ubuntu 24.04

  1. Open Terminal: Either connect via SSH or access the terminal directly.
  2. Add New User: Use the following command to add a new user. Replace username with the desired username.
   sudo adduser username

This command will prompt you to set a password and enter some optional user information (like the full name, phone number, etc.).

  1. Give Permissions: If you need the new user to have administrative privileges, you can add them to the sudo group with:
   sudo usermod -aG sudo username

Adding Users on CentOS 8

  1. Open Terminal: Either connect via SSH or access the terminal directly.
  2. Add New User: Use the following command, similar to Ubuntu, to create a new account.
   sudo adduser username
  1. Set Password: After the user is added, set a password for the new user:
   sudo passwd username
  1. Granting sudo Access: If you want to allow the new user to run commands with sudo privileges, you can either add them to the wheel group:
   sudo usermod -aG wheel username

Deleting Users

Deleting Users on Ubuntu 24.04

  1. Open Terminal: Connect to your server.
  2. Delete User: Use the following command to delete a user. Replace username with the username you want to remove.
   sudo deluser username

If you also want to remove the user’s home directory and mail spool, use:

   sudo deluser --remove-home username

Deleting Users on CentOS 8

  1. Open Terminal: Connect to your server.
  2. Delete User: To remove a user, use:
   sudo userdel username

To remove the user’s home directory along with the account, add the -r flag:

   sudo userdel -r username

Conclusion

Managing user accounts on Ubuntu 24.04 and CentOS 8 is straightforward, thanks to the command-line tools provided by these distributions. Regularly updating your user list is a key component of good system administration, especially to maintain security and efficient resource management.

By following the steps outlined above, you can easily add and remove users from your systems. Always remember to use strong passwords and review user privileges regularly to ensure your systems remain secure.

For further inquiries or tips on Linux user management, feel free to comment below or reach out on our social media channels. Happy managing!


This detailed guide should equip you with the necessary skills to manage users on both Ubuntu and CentOS effectively. For more insights on cloud hosting and Linux administration, keep visiting the Greenhost.Cloud blog!