Show Table of Contents
6.3. 既存 Linux ユーザーの制限: semanage login
Linux ユーザーが SELinux
unconfined_u ユーザーにマッピングされ (デフォルトの動作)、マッピング先の SELinux ユーザーを変更したい場合は、semanage login コマンドを使います。以下の例では、newuser という名前の新規 Linux ユーザーが作成され、SELinux user_u ユーザーにマッピングされます。
- Linux root ユーザーで
useradd newuserコマンドを実行し、ユーザー名 newuser という新規 Linux ユーザーを作成します。このユーザーはデフォルトマッピングを使用しているため、semanage login -l出力には表示されません。~]#
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 - この Linux newuser ユーザーを SELinux
user_uユーザーにマッピングするには、Linux root ユーザーで以下のコマンドを実行します。~]#
semanage login -a -s user_u newuser-aオプションは新規レコードを追加し、-sオプションは Linux ユーザーがマッピングされる SELinux ユーザーを指定します。最後の 引数であるnewuserは、指定した SELinux ユーザーにマッピングする Linux ユーザーです。 - Linux newuser ユーザーと
user_u間のマッピングを表示するには、semanage login -lコマンドを Linux root ユーザーで実行します。~]#
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 - Linux root ユーザーで
passwd newuserコマンドを実行し、Linux newuser ユーザーにパスワードを割り当てます。~]#
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. - 現行セッションから一旦ログアウトし、Linux newuser ユーザーでログインし直します。
id -Zコマンドを実行し、newuser の SELinux コンテキストを表示します。~]$
id -Zuser_u:user_r:user_t:s0 - Linux newuser のセッションからログアウトし、自分のアカウントでログインし直します。Linux newuser ユーザーが不要な場合は、Linux root ユーザーで
userdel -r newuserコマンドを実行し、そのホームディレクトリーとともに削除します。semanage login -d newuserコマンドを実行し、Linux newuser ユーザーとuser_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.