Ce contenu n'est pas disponible dans la langue sélectionnée.

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:

Procedure 6.2. Mapping Linux Users to the SELinux Users

  1. As root, create a new Linux user (newuser). Since this user uses the default mapping, it does not appear in the semanage login -l output:
    ~]# useradd newuser
    Copy to Clipboard Toggle word wrap
    ~]# semanage login -l
    
    Login Name           SELinux User         MLS/MCS Range        Service
    
    __default__          unconfined_u         s0-s0:c0.c1023       *
    root                 unconfined_u         s0-s0:c0.c1023       *
    system_u             system_u             s0-s0:c0.c1023       *
    
    Copy to Clipboard Toggle word wrap
  2. To map the Linux newuser user to the SELinux user_u user, enter the following command as root:
    ~]# semanage login -a -s user_u newuser
    Copy to Clipboard Toggle word wrap
    The -a option adds a new record, and the -s option 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.
  3. To view the mapping between the Linux newuser user and user_u, use the semanage utility again:
    ~]# semanage login -l
    
    Login Name           SELinux User         MLS/MCS Range        Service
    
    __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       *
    
    Copy to Clipboard Toggle word wrap
  4. As root, assign a password to the Linux newuser user:
    ~]# passwd newuser
    Changing password for user newuser.
    New password: Enter a password
    Retype new password: Enter the same password again
    passwd: all authentication tokens updated successfully.
    
    Copy to Clipboard Toggle word wrap
  5. Log out of your current session, and log in as the Linux newuser user. Enter the following command to view the newuser's SELinux context:
    ~]$ id -Z
    user_u:user_r:user_t:s0
    Copy to Clipboard Toggle word wrap
  6. Log out of the Linux newuser's session, and log back in with your account. If you do not want the Linux newuser user, enter the following command as root to remove it, along with its home directory:
    ~]# userdel -r newuser
    Copy to Clipboard Toggle word wrap
    As root, remove the mapping between the Linux newuser user and user_u:
    ~]# semanage login -d newuser
    Copy to Clipboard Toggle word wrap
    ~]# semanage login -l
    
    Login Name           SELinux User         MLS/MCS Range        Service
    
    __default__          unconfined_u         s0-s0:c0.c1023       *
    root                 unconfined_u         s0-s0:c0.c1023       *
    system_u             system_u             s0-s0:c0.c1023       *
    
    Copy to Clipboard Toggle word wrap
Retour au début
Red Hat logoGithubredditYoutubeTwitter

Apprendre

Essayez, achetez et vendez

Communautés

À propos de la documentation Red Hat

Nous aidons les utilisateurs de Red Hat à innover et à atteindre leurs objectifs grâce à nos produits et services avec un contenu auquel ils peuvent faire confiance. Découvrez nos récentes mises à jour.

Rendre l’open source plus inclusif

Red Hat s'engage à remplacer le langage problématique dans notre code, notre documentation et nos propriétés Web. Pour plus de détails, consultez le Blog Red Hat.

À propos de Red Hat

Nous proposons des solutions renforcées qui facilitent le travail des entreprises sur plusieurs plates-formes et environnements, du centre de données central à la périphérie du réseau.

Theme

© 2025 Red Hat