Easy Guide To Add and Remove Users on AlmaLinux 9
This tutorial aims to provide an Ultimate Guide To Add and Remove Users on AlmaLinux 9 from the command line. Users with access to your operating system can perform various tasks, including managing, installing, and updating applications. Each user has a unique ID and password. They can be added to specific groups on your server and assigned specific tasks.
In this guide on the Orcacore website, you will learn how to add new users, add them to groups, and delete users on AlmaLinux 9. This Easy Guide To Add and Remove Users on AlmaLinux 9 will provide a comprehensive overview of the process.
To effectively add and remove users on AlmaLinux 9, you must have access to your server as either a root user or a non-root user with sudo privileges. For assistance with this, you can refer to the guide on Initial Server Setup with AlmaLinux 9.
For detailed information on creating a new user with sudo privileges, follow the steps below.

Step 1 – Create a New User on AlmaLinux 9
In this step of the Easy Guide To Add and Remove Users on AlmaLinux 9, you can create a new user on your server using the adduser
command. For example, to create a new user named "orca":
adduser orca
This command automatically creates a home directory for the user, located at /home/orca
. If you want to specify a different home directory, use the -d
flag and provide the desired path:
useradd orca -d /path/to/home
Step 2 – Add the User to a Specific Group on AlmaLinux 9
You can add users to specific groups on AlmaLinux 9. Here, we add our user to the "wheel" group, which grants root privileges and allows the user to run sudo
commands.
In AlmaLinux 9, the sudoers
group is named "wheel". To add the user to this group, use the following command:
usermod -aG wheel orca
This allows the "orca" user to run commands with root privileges. To verify this, use the lid
command:
lid orca
**Output**
wheel(gid=10)
orca(gid=1000)
You can use this command to add users to different groups.
Step 3 – Set a Password for the User on AlmaLinux 9
By default, newly created users don’t have passwords. You can set a password so they can log in to the server. Use the passwd
command. Here, we assign a password to the user "orca" with the following command on AlmaLinux:
passwd orca
You will be prompted to enter a new password and verify it.
**Output**
Changing password for user orca.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
You can also check the user’s ID and groups with the command below:
id orca
**Output**
uid=1000(orca) gid=1000(orca) groups=1000(orca),10(wheel)
Step 4 – Remove Users on AlmaLinux 9
In this step of the Easy Guide To Add and Remove Users on AlmaLinux 9, if you want to remove a specific user from your AlmaLinux 9 system, use the userdel
command.
For example, to delete the "orca" user, run the command:
userdel orca
This command does not remove the user’s home directory. To delete the home directory as well, use the -r
flag in your command:
userdel -r orca
That’s it! These are the basic steps to adding and deleting users on AlmaLinux 9.
You can find more information, options, and usage examples by running the help commands:
# useradd --help
# passwd --help
# usermod --help
# userdel --help
Conclusion
At this point, you have learned to use Linux Commands for an ultimate guide to Add and Remove Users on AlmaLinux 9. You can easily use the useradd
command to add a user and the userdel
command to delete users.
Hope you enjoyed it. You may be interested in these articles:
Install Froxlor Server Management on AlmaLinux 9
AlmaLinux vs CloudLinux – Which One is Better For Web Hosting
Alternative Solutions for User Management on AlmaLinux 9
While the command-line tools like useradd
, usermod
, and userdel
are fundamental for user management, alternative solutions exist that can offer different functionalities or cater to specific needs. Here are two different approaches:
1. Using Cockpit Web Console for User Management
Cockpit is a web-based interface for managing your AlmaLinux server. It provides a graphical user interface (GUI) for performing various administrative tasks, including user management.
Explanation:
Cockpit simplifies user management by providing a visual interface. Instead of remembering command-line syntax, you can create, modify, and delete users through a web browser. This can be particularly helpful for users who are not comfortable with the command line. It also handles the underlying commands, making it less error-prone for beginners.
Steps:
-
Install Cockpit: If Cockpit is not already installed, you can install it using the following command:
sudo dnf install cockpit
-
Enable and Start Cockpit:
sudo systemctl enable --now cockpit.socket
-
Access Cockpit: Open a web browser and navigate to
https://your_server_ip:9090
. You may need to accept a self-signed certificate if you haven’t configured a proper SSL certificate. -
Log In: Log in with your root user credentials or a user with sudo privileges.
-
Navigate to Accounts: In the Cockpit interface, navigate to the "Accounts" section.
-
Manage Users: From the "Accounts" section, you can add new users, edit existing users (including their groups and passwords), and delete users. The interface is self-explanatory, guiding you through each step.
Advantages:
- User-Friendly GUI: Simplifies user management for those unfamiliar with the command line.
- Remote Management: Access your server and manage users from any web browser.
- Centralized Management: Cockpit provides a single interface for managing various aspects of your server, not just users.
Disadvantages:
- Overhead: Cockpit adds a layer of overhead to the server, although it is generally minimal.
- GUI Dependency: Requires a web browser and network access.
2. Utilizing Ansible for Automated User Management
Ansible is an automation tool that can be used to manage and configure systems. It allows you to define user management tasks in a declarative way, making it easy to automate the process across multiple servers. This approach is particularly useful for managing users on a large scale or when ensuring consistency across multiple systems.
Explanation:
Instead of manually adding or removing users on each server, you can create an Ansible playbook that defines the desired state of users on your systems. Ansible will then ensure that all servers match this state. This is ideal for environments with many servers or when you need to ensure consistent user configurations.
Code Example (Ansible Playbook):
Create a file named user_management.yml
with the following content:
---
- hosts: all
become: true
tasks:
- name: Add a new user
user:
name: deploy
comment: Deploy User
uid: 1001
group: deploy
shell: /bin/bash
password: "$6$rounds=656000$K1gYf.oJvL/Lq56j$yK767n6QnUu.1j0g7rU1/z/Ua5zW8hM8k3Qn7x0X5z5j9g3Q0i8f.f6wY0a" # Hashed Password
state: present
- name: Ensure user is in the 'wheel' group (sudo access)
user:
name: deploy
groups: wheel
append: yes
- name: Remove a user
user:
name: testuser
state: absent
remove: yes
Explanation of the Playbook:
hosts: all
: This specifies that the playbook should be executed on all hosts defined in your Ansible inventory.become: true
: This instructs Ansible to execute the tasks with elevated privileges (sudo).tasks:
: This section defines the individual tasks to be performed.Add a new user
: This task uses theuser
module to create a new user named "deploy". It sets various attributes like the user’s comment, UID, primary group, shell, and a hashed password. Important: Never store passwords in plain text. Usemkpasswd
or a similar tool to generate a secure password hash.Ensure user is in the 'wheel' group
: This task adds the "deploy" user to the "wheel" group, granting sudo access.append: yes
ensures that the user is added to the group without removing them from any existing groups.Remove a user
: This task uses theuser
module to remove a user named "testuser".state: absent
ensures that the user is removed if it exists, andremove: yes
ensures that the user’s home directory is also removed.
Running the Playbook:
- Install Ansible: If Ansible is not already installed, install it using your distribution’s package manager. For AlmaLinux:
sudo dnf install ansible
. - Configure Ansible Inventory: Create an Ansible inventory file (e.g.,
/etc/ansible/hosts
) that lists the servers you want to manage. -
Run the Playbook: Execute the playbook using the following command:
ansible-playbook user_management.yml
Advantages:
- Automation: Automates user management tasks, saving time and effort.
- Idempotence: Ansible ensures that the desired state is achieved, regardless of the current state. It only makes changes if necessary.
- Scalability: Easily manage users across multiple servers.
- Configuration as Code: Defines user configurations in a declarative way, making it easier to track changes and maintain consistency.
Disadvantages:
- Learning Curve: Requires learning Ansible syntax and concepts.
- Initial Setup: Requires setting up Ansible and configuring an inventory.
These alternative solutions offer different approaches to user management on AlmaLinux 9, catering to varying needs and preferences. Choosing the right solution depends on factors such as the size of your environment, your technical expertise, and your specific requirements. The Easy Guide To Add and Remove Users on AlmaLinux 9 provided a good foundation. Understanding these alternatives expands your toolset for managing your AlmaLinux systems effectively.