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:
- Access to a terminal with root or sudo privileges on your server.
- Familiarity with basic Linux commands.
Adding Users
Adding Users on Ubuntu 24.04
- Open Terminal: Either connect via SSH or access the terminal directly.
- Add New User: Use the following command to add a new user. Replace
usernamewith the desired username.
sudo adduser usernameThis command will prompt you to set a password and enter some optional user information (like the full name, phone number, etc.).
- Give Permissions: If you need the new user to have administrative privileges, you can add them to the
sudogroup with:
sudo usermod -aG sudo usernameAdding Users on CentOS 8
- Open Terminal: Either connect via SSH or access the terminal directly.
- Add New User: Use the following command, similar to Ubuntu, to create a new account.
sudo adduser username- Set Password: After the user is added, set a password for the new user:
sudo passwd username- Granting sudo Access: If you want to allow the new user to run commands with sudo privileges, you can either add them to the
wheelgroup:
sudo usermod -aG wheel usernameDeleting Users
Deleting Users on Ubuntu 24.04
- Open Terminal: Connect to your server.
- Delete User: Use the following command to delete a user. Replace
usernamewith the username you want to remove.
sudo deluser usernameIf you also want to remove the user’s home directory and mail spool, use:
sudo deluser --remove-home usernameDeleting Users on CentOS 8
- Open Terminal: Connect to your server.
- Delete User: To remove a user, use:
sudo userdel usernameTo remove the user’s home directory along with the account, add the -r flag:
sudo userdel -r usernameConclusion
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!