Chapter 9. Managing users and groups Preventing unauthorized access to files and processes requires accurate user and group management. If you do not manage accounts centrally or you require a user account or group only on a specific system, you can create them locally on a host. 9.1. Introduction to managing user and group accounts The control of users and groups is a core element of Red Hat Enterprise Linux (RHEL) system administration. Each RHEL user has distinct login credentials and can be assigned to various groups to customize their system privileges. 9.1.1. Introduction to users and groups A user who creates a file is the owner of that file and the group owner of that file. The file is assigned separate read, write, and execute permissions for the owner, the group, and those outside that group. The file owner can be changed only by the root user. Access permissions to the file can be changed by both the root user and the file owner. A regular user can change group ownership of a file they own to a group of which they are a member of. Each user is associated with a unique numerical identification number called user ID ( UID ). Each group is associated with a group ID ( GID ). Users within a group share the same permissions to read, write, and execute files owned by that group. 9.1.2. Configuring reserved user and group IDs By default, RHEL reserves user and group IDs below 1000 for system users and groups. You can find the reserved user and group IDs in the setup package. The UID's and GID's of users and groups created before you changed the UID_MIN and GID_MIN values do not change. The reserved user and group IDs are documented in the: To assign IDs to the new users and groups starting at 5000, as the reserved range can increase in the future. Modify the UID_MIN and GID_MIN parameters in the /etc/login.defs file to define a start ID other than the defaults (1000). Warning Do not raise IDs reserved by the system above 1000 by changing SYS_UID_MAX to avoid conflict with systems that retain the 1000 limit. Procedure Open the /etc/login.defs file in an editor. Set the UID_MIN variable, for example: Set the GID_MIN variable, for example: The dynamically assigned UIDs and GIDs for the regular users now start at 5000. 9.1.3. User private groups RHEL uses the user private group ( UPG ) system configuration, which makes Linux groups easier to manage. A user private group is created whenever a new user is added to the system. The user private group has the same name as the user for which it was created and that user is the only member of the user private group. UPGs simplify the collaboration on a project between multiple users. In addition, UPG system configuration makes it safe to set default permissions for a newly created file or directory, as it allows both the user, and the group this user is a part of, to make modifications to the file or directory. A list of all local groups is stored in the /etc/group configuration file. 9.2. Getting started with managing user accounts Red Hat Enterprise Linux is a multi-user operating system, which enables multiple users on different computers to access a single system installed on one machine. Every user operates under its own account, and managing user accounts thus represents a core element of Red Hat Enterprise Linux system administration. The following are the different types of user accounts: Normal user accounts: Normal accounts are created for users of a particular system. Such accounts can be added, removed, and modified during normal system administration. System user accounts: System user accounts represent a particular applications identifier on a system. Such accounts are generally added or manipulated only at software installation time, and they are not modified later. Warning System accounts are presumed to be available locally on a system. If these accounts are configured and provided remotely, such as in the instance of an LDAP configuration, system breakage and service start failures can occur. For system accounts, user IDs below 1000 are reserved. For normal accounts, you can use IDs starting at 1000. To define the min/max IDs for users and groups, system users and system groups, see the /etc/login.defs file. Group: A group is an entity which ties together multiple user accounts for a common purpose, such as granting access to particular files. 9.2.1. Managing accounts and groups using command line tools Use the following basic command-line tools to manage user accounts and groups. Procedure Create a new user account: Assign a new password to a user account belonging to example.user : Add a user to a group: Additional resources useradd(8) , passwd(1) , and usermod(8) man pages 9.3. Managing users from the command line You can manage users and groups using the command-line interface ( CLI ). This enables you to add, remove, and modify users and user groups in Red Hat Enterprise Linux environment. 9.3.1. Adding a new user from the command line You can use the useradd utility to add a new user. Prerequisites You have Root access Procedure Add a new user, use: Replace options with the command-line options for the useradd command, and replace username with the name of the user. Example 9.1. Adding a new user To add the user sarah with user ID 5000 , use: Verification To verify the new user is added, use the id utility. The command returns: Additional resources useradd man page 9.3.2. Adding a new group from the command line You can use the groupadd utility to add a new group. Prerequisites You have Root access Procedure To add a new group, use: Replace options with the command-line options for the groupadd command, and replace group-name with the name of the group. Example 9.2. Adding a new group To add the group sysadmins with group ID 5000 , use: Verification To verify the new group is added, use the tail utility. The command returns: Additional resources groupadd man page 9.3.3. Adding a user to a supplementary group from the command line You can add a user to a supplementary group to manage permissions or enable access to certain files or devices. Prerequisites You have root access Procedure To add a group to the supplementary groups of the user, use: Verification To verify the new groups is added to the supplementary groups of the user sysadmin , use: 9.3.4. Creating a group directory Under the UPG system configuration, you can apply the set-group identification permission ( setgid bit) to a directory. The setgid bit makes managing group projects that share a directory simpler. When you apply the setgid bit to a directory, files created within that directory are automatically assigned to a group that owns the directory. Any user that has the permission to write and execute within this group can now create, modify, and delete files in the directory. Prerequisites You have Root access Procedure Create a directory: Create a group: Add users to the group: Associate the user and group ownership of the directory with the group-name group: Set the write permissions to allow the users to create and modify files and directories and set the setgid bit to make this permission be applied within the directory: Verification To verify the correctness of set permissions, use: The command returns: 9.3.5. Removing a user on the command line You can remove a user account by using the command line. In addition, below mentioned are the commands to remove the user account, and optionally remove the user data and metadata, such as their home directory and configuration files. You have root access. The user currently exists. Ensure that the user is logged out: To only remove the user account, and not the user data: To remove the user, the data, and the metadata: Remove the user, their home directory, their mail spool, and their SELinux user mapping: Remove additional user metadata: This directory stores information that the system needs about the user before the home directory is available. Depending on the system configuration, the home directory might not be available until the user authenticates at the login screen. Important If you do not remove this directory and you later recreate the same user, the recreated user will still use certain settings inherited from the removed user. Additional resources userdel(8) man page 9.4. Managing user accounts in the web console The RHEL web console provides a graphical interface for adding, editing, and removing system user accounts. You can also set password expiration and terminate user sessions in the web console. 9.4.1. Adding new accounts by using the web console You can add user accounts to the system and set administration rights to the accounts through the RHEL web console. Prerequisites You have installed the RHEL 9 web console. You have enabled the cockpit service. Your user account is allowed to log in to the web console. For instructions, see Installing and enabling the web console . Procedure Log in to the RHEL 9 web console. For details, see Logging in to the web console . Click Accounts . Click Create New Account . In the Full Name field, enter the full name of the user. The RHEL web console automatically suggests a user name from the full name and fills it in the User Name field. If you do not want to use the original naming convention consisting of the first letter of the first name and the whole surname, update the suggestion. In the Password/Confirm fields, enter the password and retype it for verification that your password is correct. The color bar below the fields shows you the security level of the entered password, which does not allow you to create a user with a weak password. Click Create to save the settings and close the dialog box. Select the newly created account. In the Groups drop-down menu, select the groups that you want to add to the new account. Verification You can see the new account in the Accounts settings and you can use its credentials to connect to the system. 9.4.2. Enforcing password expiration in the web console By default, user accounts have set passwords to never expire. You can set system passwords to expire after a defined number of days. When the password expires, the user must change its password at the login attempt before the user can access the system. Prerequisites You have installed the RHEL 9 web console. You have enabled the cockpit service. Your user account is allowed to log in to the web console. For instructions, see Installing and enabling the web console . Procedure Log in to the RHEL 9 web console. Click Accounts . Select the user account for which you want to enforce password expiration. Click edit on the Password line. In the Password expiration dialog box, select Require password change every ... days and enter a positive whole number representing the number of days after which the password expires. Click Change . The web console immediately shows the date of the future password change request on the Password line. 9.5. Editing user groups using the command line A user belongs to a certain set of groups that allow a logical collection of users with a similar access to files and folders. You can edit the primary and supplementary user groups from the command line to change the user's permissions. 9.5.1. Primary and supplementary user groups A group is an entity which ties together multiple user accounts for a common purpose, such as granting access to particular files. On RHEL, user groups can act as primary or supplementary. Primary and supplementary groups have the following properties: Primary group Every user has just one primary group at all times. You can change the user's primary group. Supplementary groups You can add an existing user to an existing supplementary group to manage users with the same security and access privileges within the group. Users can be members of zero, one, or multiple supplementary groups. 9.5.2. Listing the primary and supplementary groups of a user You can list the groups of users to see which primary and supplementary groups they belong to. Procedure Display the names of the primary and any supplementary group of a user: If you do not provide a user name, the command displays the group membership for the current user. The first group is the primary group followed by the optional supplementary groups. Example 9.3. Listing of groups for user sarah: The output displays: User sarah has a primary group sarah and is a member of supplementary groups wheel and developer . 9.5.3. Changing the primary group of a user You can change the primary group of an existing user to a new group. Prerequisites: root access The new group must exist Procedure Change the primary group of a user: Note When you change a user's primary group, the command also automatically changes the group ownership of all files in the user's home directory to the new primary group. You must fix the group ownership of files outside of the user's home directory manually. Verify that you changed the primary group of the user: 9.5.4. Adding a user to a supplementary group from the command line You can add a user to a supplementary group to manage permissions or enable access to certain files or devices. Prerequisites You have root access Procedure To add a group to the supplementary groups of the user, use: Verification To verify the new groups is added to the supplementary groups of the user sysadmin , use: 9.5.5. Removing a user from a supplementary group You can remove an existing user from a supplementary group to limit their permissions or access to files and devices. Prerequisites You have root access Procedure Remove a user from a supplementary group: Verification Verify that you removed the user sarah from the secondary group developers: 9.5.6. Changing all of the supplementary groups of a user You can overwrite the list of supplementary groups that you want the user to remain a member of. Prerequisites You have root access. The supplementary groups must exist. Procedure Overwrite a list of user's supplementary groups: To add the user to several supplementary groups at once, separate the group names using commas and no intervening spaces. For example: wheel,developer . Important If the user is currently a member of a group that you do not specify, the command removes the user from the group. Verification Verify that you set the list of the supplementary groups correct: 9.6. Changing and resetting the root password If the existing root password is no longer satisfactory, you can change it both as the root user and a non-root user. 9.6.1. Changing the root password as the root user You can use the passwd command to change the root password as the root user. Prerequisites You have Root access Procedure To change the root password, use: You are prompted to enter your current password before you can change it. 9.6.2. Changing or resetting the forgotten root password as a non-root user You can use the passwd command to change or reset the forgotten root password as a non-root user. Prerequisites You are able to log in as a non-root user. You have permissions to execute commands as root by using sudo . Procedure To change or reset the root password as a non-root user that belongs to the wheel group, use: You are prompted to enter your current non-root password before you can change the root password. 9.6.3. Resetting the root password If you are unable to log in as root user and have no non-root user with sudo permissions, you can reset the root password or do not belong to the administrative wheel group, you can reset the root password by booting the system into the special mode. In this mode, the boot process stops before the system hands over the control from the initramfs to the actual system. Procedure Reboot the system and, on the GRUB boot screen, press the e key to interrupt the boot process. The kernel boot parameters appear. Set the cursor to the end of the line that starts with linux . Append rd.break to the end of the line that starts with linux . Press Ctrl+x to start the system with the changed parameters. The switch_root prompt appears. Remount the file system as writable: By default, the file system is mounted as read-only in the /sysroot directory. Remounting the file system as writable allows you to change the password. Enter the chroot environment: Reset the root password: Follow the instructions displayed by the command line to finalize the change of the root password. Enable the SELinux relabeling process on the system boot: Exit the chroot environment: Exit the switch_root prompt, to reboot the system: Wait until the SELinux relabeling process is finished. Note that relabeling a large disk can take a long time. The system reboots automatically when the process is complete. Verification Log in as the root user by using the new root password. Optional: Display the user name associated with the current effective user ID:

Commands:
/usr/share/doc/setup/uidgid
Min/max values for automatic uid selection in useradd # UID_MIN 5000
Min/max values for automatic gid selection in groupadd # GID_MIN 5000
useradd example.user
passwd example.user
usermod -a -G example.group example.user
useradd <options> <username>
useradd -u 5000 sarah
id sarah
uid=5000(sarah) gid=5000(sarah) groups=5000(sarah)
groupadd options group-name
groupadd -g 5000 sysadmins
getent group sysadmin
sysadmins:x:5000:
usermod --append -G <group_name> <username>
groups <username>
mkdir <directory-name>
groupadd <group-name>
usermod --append -G <group_name> <username>
chgrp <group_name> <directory>
chmod g+rwxs <directory>
ls -ld <directory>
*drwx__rws__r-x.* 2 root _group-name_ 6 Nov 25 08:45 _directory-name_
loginctl terminate-user user-name
userdel user-name
userdel --remove --selinux-user user-name
rm -rf /var/lib/AccountsService/users/ user-name
groups user-name
groups sarah
sarah : sarah wheel developer
usermod -g <group-name> <user-name>
groups <username>
usermod --append -G <group_name> <username>
groups <username>
gpasswd -d <user-name> <group-name>
groups <username>
usermod -G <group-names> <username>
groups <username>
passwd
sudo passwd root
load_video set gfx_payload=keep insmod gzio linux (USDroot)/vmlinuz-5.14.0-70.22.1.e19_0.x86_64 root=/dev/mapper/rhel-root ro crash kernel=auto resume=/dev/mapper/rhel-swap rd.lvm.lv/swap rhgb quiet initrd (USDroot)/initramfs-5.14.0-70.22.1.e19_0.x86_64.img USDtuned_initrd
mount -o remount,rw /sysroot
chroot /sysroot
passwd
touch /.autorelabel
exit
exit
whoami