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

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.