Show Table of Contents
6.3. Confining Existing Linux Users: semanage login
If a Linux user is mapped to the SELinux
unconfined_u user (the default behavior), and you would like to change which SELinux user they are mapped to, use the semanage login command. The following example creates a new Linux user named newuser, then maps that Linux user to the SELinux user_u user:
- As the Linux root user, run the
useradd newusercommand to create a new Linux user (newuser). Since this user uses the default mapping, it does not appear in thesemanage login -loutput:~]#
useradd newuser~]#semanage login -lLogin Name SELinux User MLS/MCS Range __default__ unconfined_u s0-s0:c0.c1023 root unconfined_u s0-s0:c0.c1023 system_u system_u s0-s0:c0.c1023 - To map the Linux
newuseruser to the SELinuxuser_uuser, run the following command as the Linux root user:~]#
semanage login -a -s user_u newuserThe-aoption adds a new record, and the-soption specifies the SELinux user to map a Linux user to. The last argument,newuser, is the Linux user you want mapped to the specified SELinux user. - To view the mapping between the Linux
newuseruser anduser_u, run thesemanage login -lcommand as the Linux root user:~]#
semanage login -lLogin Name SELinux User MLS/MCS Range __default__ unconfined_u s0-s0:c0.c1023 newuser user_u s0 root unconfined_u s0-s0:c0.c1023 system_u system_u s0-s0:c0.c1023 - As the Linux root user, run the
passwd newusercommand to assign a password to the Linuxnewuseruser:~]#
passwd newuserChanging password for user newuser. New password: Enter a password Retype new password: Enter the same password again passwd: all authentication tokens updated successfully. - Log out of your current session, and log in as the Linux
newuseruser. Run theid -Zcommand to view thenewuser's SELinux context:~]$
id -Zuser_u:user_r:user_t:s0 - Log out of the Linux
newuser's session, and log back in with your account. If you do not want the Linuxnewuseruser, run theuserdel -r newusercommand as the Linux root user to remove it, along with its home directory. Run thesemanage login -d newusercommand to remove the mapping between the Linuxnewuseruser anduser_u:~]#
userdel -r newuser~]#semanage login -d newuser~]#semanage login -lLogin Name SELinux User MLS/MCS Range __default__ unconfined_u s0-s0:c0.c1023 root unconfined_u s0-s0:c0.c1023 system_u system_u s0-s0:c0.c1023

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.