Preventing unauthorized access to files and processes requires an 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 this host.
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.
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.
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. To view reserved user and group IDs, use:
cat /usr/share/doc/setup*/uidgid
It is recommended to assign IDs to the new users and groups starting at 5000, as the reserved range can increase in the future.
To make the IDs assigned to new users start at 5000 by default, modify the UID_MIN and GID_MIN parameters in the /etc/login.defs file.
Procedure
To modify and make the IDs assigned to new users start at 5000 by default:
# Min/max values for automatic uid selection in useradd # UID_MIN 1000
# Min/max values for automatic uid selection in useradd # UID_MIN 5000
# Min/max values for automatic gid selection in groupadd # GID_MIN 1000
# Min/max values for automatic gid selection in groupadd # GID_MIN 5000
The dynamically assigned UIDs and GIDs for the regular users now start at 5000.
The UID’s and GID’s of users and groups created before you changed the UID_MIN and GID_MIN values do not change.
This will allow new user’s group to have same 5000+ ID as UID and GID.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.
RHEL uses the user private group ( UPG ) system configuration, which makes UNIX 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 groups is stored in the /etc/group configuration file.
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:
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.
Use the following basic command-line tools to manage user accounts and groups.
$ id uid=1000(example.user) gid=1000(example.user) groups=1000(example.user),10(wheel) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
# useradd example.user
# passwd example.user
# usermod -a -G example.group example.user
Additional resources
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.
You can use the useradd utility to add a new user.
Prerequisites
Procedure
# useradd options username
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:# useradd -u 5000 sarah
Verification
# id sarah
The output returns:
uid=5000(sarah) gid=5000(sarah) groups=5000(sarah)
Additional resources
You can use the groupadd utility to add a new group.
Prerequisites
Procedure
# groupadd options group-name
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:# groupadd -g 5000 sysadmins
Verification
# tail /etc/group
The output returns:
sysadmins:x:5000:
Additional resources
You can add a user to a supplementary group to manage permissions or enable access to certain files or devices.
Prerequisites
Procedure
# usermod --append -G group-name username
Replace group-name with the name of the group, and replace username with the name of the user.
Example 9.3. Adding a user to a supplementary group
To add the user sysadmin to the group system-administrators , use:
# usermod --append -G system-administrators sysadmin
Verification
# groups sysadmin
The output displays:
sysadmin : sysadmin system-administrators
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.
The following section describes how to create group directories.
Prerequisites
Procedure
# mkdir directory-name
# groupadd group-name
# usermod --append -G group-name username
# chgrp group-name directory-name
# chmod g+rwxs directory-name
Verification
# ls -ld directory-name
Replace directory-name with the name of the directory. The output returns:
drwxrwsr-x. 2 root group-name 6 Nov 25 08:45 directory-name
You can remove a user account using the command line. In addition to removing the user account, you can optionally remove the user data and metadata, such as their home directory and configuration files.
Prerequisites
# loginctl terminate-user user-name
Procedure
# userdel user-name
# userdel --remove --selinux-user user-name
# rm -rf /var/lib/AccountsService/users/user-name
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.
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
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.
You can add user accounts to the system and set administration rights to the accounts through the RHEL web console.
Prerequisites
Procedure
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 next login attempt will prompt for a password change.
Prerequisites
Procedure
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.
A group is an entity which ties together multiple user accounts for a common purpose, such as granting access to particular files.
On Linux, user groups can act as primary or supplementary. Primary and supplementary groups have the following properties:
Primary groupYou can list the groups of users to see which primary and supplementary groups they belong to.
Procedure
$ groups user-name
Replace user-name with the name of the 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.4. Listing of groups for user sarah:$ groups sarah
The output displays:
sarah : sarah wheel developerUser sarah has a primary group sarah and is a member of supplementary groups wheel and developer . Example 9.5. Listing of groups for user marc:
$ groups marc
The output displays:
marc : marcUser marc has only a primary group marc and no supplementary groups.
You can change the primary group of an existing user to a new group.
Prerequisites:
Procedure
# usermod -g group-name user-name
Replace group-name with the name of the new primary group, and replace user-name with the name of the user.
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.
Example 9.6. Example of changing the primary group of a user:If the user sarah belongs to the primary group sarah1 , and you want to change the primary group of the user to sarah2 , use:
# usermod -g sarah2 sarah
Verification
$ groups sarah
The output displays:
sarah : sarah2
You can add a user to a supplementary group to manage permissions or enable access to certain files or devices.
Prerequisites
Procedure
# usermod --append -G group-name username
Replace group-name with the name of the group, and replace username with the name of the user.
Example 9.7. Adding a user to a supplementary group
To add the user sysadmin to the group system-administrators , use:
# usermod --append -G system-administrators sysadmin
Verification
# groups sysadmin
The output displays:
sysadmin : sysadmin system-administrators
You can remove an existing user from a supplementary group to limit their permissions or access to files and devices.
Prerequisites
Procedure
# gpasswd -d user-name group-name
Replace user-name with the name of the user, and replace group-name with the name of the supplementary group.
Example 9.8. Removing user from a supplementary groupIf the user sarah has a primary group sarah2 , and belongs to the secondary groups wheel and developers , and you want to remove that user from the group developers , use:
# gpasswd -d sarah developers
Verification
$ groups sarah
The output displays:
sarah : sarah2 wheel
You can overwrite the list of supplementary groups that you want the user to remain a member of.
Prerequisites
Procedure
# usermod -G group-names username
Replace group-names with the name of one or more 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 . Replace user-name with the name of the user.
If the user is currently a member of a group that you do not specify, the command removes the user from the group.
Example 9.9. Changing the list of supplementary groups of a userIf the user sarah has a primary group sarah2 , and belongs to the supplementary group wheel , and you want the user to belong to three more supplementary groups developer , sysadmin , and security , use:
# usermod -G wheel,developer,sysadmin,security sarah
Verification
# groups sarah
The output displays:
sarah : sarah2 wheel developer sysadmin security
If the existing root password is no longer satisfactory or is forgotten, you can change or reset it both as the root user and a non-root user.
You can use the passwd command to change the root password as the root user.
Prerequisites
Procedure
# passwd
You can use the passwd command to change or reset the forgotten root password as a non-root user.
Prerequisites
Procedure
$ sudo passwd root
If you are unable to log in as a non-root user or do not belong to the administrative wheel group, you can reset the root password on boot by switching into a specialized chroot jail environment.
Procedure
load_video set gfx_payload=keep insmod gzio linux ($root)/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 ($root)/initramfs-5.14.0-70.22.1.e19_0.x86_64.img $tuned_initrd
linux ($root)/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
linux ($root)/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 rd.break
mount -o remount,rw /sysroot
chroot /sysroot
passwd
touch /.autorelabel
exit
exit
Verification
$ su
# whoami