OS の認証周りの設定を変更してみよう ~authselect について~

◆ Live配信スケジュール ◆
サイオステクノロジーでは、Microsoft MVPの武井による「わかりみの深いシリーズ」など、定期的なLive配信を行っています。
⇒ 詳細スケジュールはこちらから
⇒ 見逃してしまった方はYoutubeチャンネルをご覧ください
【5/21開催】Azure OpenAI ServiceによるRAG実装ガイドを公開しました
生成AIを活用したユースケースで最も一番熱いと言われているRAGの実装ガイドを公開しました。そのガイドの紹介をおこなうイベントです!!
https://tech-lab.connpass.com/event/315703/

こんにちは。サイオステクノロジーの橋本です。

今回は RHEL 8、9 において /etc/pam.d/ 配下のファイルや /etc/nsswitch.conf
といった認証周りの設定変更方法について実例を挙げつつ説明していきます。
※今回はそれぞれのファイルの説明は行いません。

ファイルを直接編集しているワイルドな方は今一度手順を見直してください。

時間がない人向けに

大体の場合 root ユーザで /etc/authselect/ 配下の設定を変更し
authselect apply-changes コマンドを実行すれば設定は反映されます。

前提

/etc/pam.d/ 配下のファイルや /etc/nsswitch.conf を直接編集することは推奨されていません。

設定ファイルを間接的に編集し、authselect コマンドを用いて設定を反映させる必要があります。
※似た考え方をするコマンドに GRUB2 の grub2-mkconfig コマンドなどがあります。
サーバの根幹に関わる設定なので安全な設定変更方法を実現しているわけです。

nsswitch.conf の以下の項目を編集したい場合は、新しくプロファイルを作成する必要があります。
passwd、
group
netgroup
automount
services
今回は passwd も変更したいので新しいプロファイルを作成します。

よく使うコマンド

RHEL 8、9 では認証周りの設定をプロファイルという形で複数保持することが
可能です。複数ある中から任意のプロファイルを一つ選んで利用するわけです。

まずは利用可能なプロファイル一覧を確認し、
現在選択されているプロファイルとその設定内容を確認しましょう。

・利用な可能なプロファイル一覧を表示

# authselect list
- minimal Local users only for minimal installations
- sssd Enable SSSD for system authentication (also for local users only)
- winbind Enable winbind for system authentication
#

・現在選択されているプロファイルを確認

# authselect current
プロファイル ID: sssd
有効な機能: なし
#

・プロファイルの内容を確認

# authselect test sssd
ファイル /etc/nsswitch.conf:
# If you want to make changes to nsswitch.conf please modify
# /etc/authselect/user-nsswitch.conf and run 'authselect apply-changes'.
#
# Note that your changes may not be applied as they may be
# overwritten by selected profile. Maps set in the authselect
~後略~

設定の変更

まずは新しいプロファイルを作成しましょう。

# authselect create-profile newprofile --base-on sssd
/etc/authselect/custom/newprofile で新規のプロファイルが作成されました
#

上記コマンドでプロファイル sssd をベースとした新しいプロファイルが作成されました。
この段階では「sssd」と「newprofile」の間に設定差はありません。

newprofile の設定内容は /etc/authselect/custom/newprofile 配下にあります。

# ls -la /etc/authselect/custom/newprofile
合計 52
drwxr-xr-x. 2 root root 4096 4月 22 14:36 .
drwxr-xr-x. 3 root root 24 4月 22 14:36 ..
-rw-r--r--. 1 root root 4633 4月 22 14:36 README
-rw-r--r--. 1 root root 3248 4月 22 14:36 REQUIREMENTS
-rw-r--r--. 1 root root 540 4月 22 14:36 dconf-db
-rw-r--r--. 1 root root 279 4月 22 14:36 dconf-locks
-rw-r--r--. 1 root root 2461 4月 22 14:36 fingerprint-auth
-rw-r--r--. 1 root root 505 4月 22 14:36 nsswitch.conf
-rw-r--r--. 1 root root 3732 4月 22 14:36 password-auth
-rw-r--r--. 1 root root 340 4月 22 14:36 postlogin
-rw-r--r--. 1 root root 2355 4月 22 14:36 smartcard-auth
-rw-r--r--. 1 root root 4778 4月 22 14:36 system-auth
#

pam 配下のファイル、例えば system-auth の設定を変更したい場合は、
/etc/authselect/custom/newprofile 配下の system-auth を編集した上で、
プロファイル「newprofile」を適用すればいいわけです。

・変更前
password sufficient pam_unix.so sha512 shadow {if not "without-nullok":nullok} use_authtok
・変更後 password sufficient pam_unix.so sha512 shadow {if not "without-nullok":nullok} use_authtok remember=5

nsswitch.conf の設定の変更

さて問題は一部の nsswitch.conf の設定です。
項目によって設定変更方法が異なります。

以下の項目は /etc/authselect/custom/newprofile/nsswitch.conf で
設定を編集する必要があります。

passwd
group
netgroup
automount
services

・変更前
passwd: {if "with-files-domain":sss files|files sss} systemd {exclude if "with-custom-passwd"}
・変更後
passwd: files ldap

設定の内容を確認してみると意図した内容となっているみたいです。

# authselect test custom/newprofile | egrep "password sufficient|passwd: files ldap"
passwd: files ldap
password sufficient pam_unix.so sha512 shadow nullok use_authtok remember=5
password sufficient pam_sss.so use_authtok
password sufficient pam_unix.so sha512 shadow nullok use_authtok
password sufficient pam_sss.so use_authtok
#

プロファイルの変更

この段階でプロファイルを変更してみましょう

# authselect select custom/newprofile
プロファイル "custom/newprofile" が設定されました。
以下の nsswitch マップはプロファイルで上書きされます:
- passwd
- group
- netgroup
- automount
- services

Make sure that SSSD service is configured and enabled. See SSSD documentation for more information.

#

前述の 5 項目 (passwd など) 以外の shadow などは

/etc/authselect/user-nsswitch.conf で行う必要があります。

・編集前
passwd: sss files systemd
shadow: files

・編集後
passwd: sss files systemd
shadow: files ldap

passwd や group などは /etc/authselect/user-nsswitch.conf を編集しても設定は反映されません。
/etc/authselect/custom/newprofile/nsswitch.conf を編集しましょう。
※設定するファイルがいろいろ分かれているのはちょっと分かりにくいですね。。。。

設定の変更反映

この後、authselect apply-changes で変更した設定を変更させます。

# authselect apply-changes
変更は正常に適用されました。
#

今回は authselect について説明しました。
私が調べた限り事例などは少なく手探りで調べる必要があるコマンドだったので、
どなたかのお役に立てればと思います。

PAM や nsswitch.conf はサーバの認証周りの根幹に関わるので、
慎重に設定してください。

補足
authselect は RHEL 8 以降のコマンドとなります。
RHEL 7 以前は authconfig でした。

アバター画像
About 橋本 9 Articles
OSS サポートエンジニア。前職ではインフラエンジニアとしてサーバ運用なんかもしていました。現在は検証のため日々サーバを作っては壊す日々です。
ご覧いただきありがとうございます! この投稿はお役に立ちましたか?

役に立った 役に立たなかった

0人がこの投稿は役に立ったと言っています。


ご覧いただきありがとうございます。
ブログの最新情報はSNSでも発信しております。
ぜひTwitterのフォロー&Facebookページにいいねをお願い致します!



>> 雑誌等の執筆依頼を受付しております。
   ご希望の方はお気軽にお問い合わせください!

Be the first to comment

Leave a Reply

Your email address will not be published.


*


質問はこちら 閉じる