0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

SSSDで統合的なLinuxユーザー管理 4. クライアントの構築 Proxmox VEの場合

0
Last updated at Posted at 2026-06-27

SSSDの構築

sssd-xxx.socketを無効化していますが、以下の事象の解消を目的にしたものです。

ca_cert.crtを/usr/local/share/ca-certificates/以下にコピー済と仮定します。
パスワードレスsudoを行う場合はlibpam-ssh-agent-authもインストールします。

# update-ca-certificates
# apt install sudo libsss-sudo sssd sssd-tools oddjob-mkhomedir
# systemctl disable sssd-nss.socket sssd-pam.socket sssd-ssh.socket sssd-sudo.socket
# pam-auth-update

pam-auth-updateでは「SSS authentication」と「Create home directory on login」を有効にします。
image.png
他の例と定義ファイルは同じです。

/etc/sssd/sssd.conf
[sssd]
services = nss, pam, sudo, ssh
domains = default

[sudo]

[domain/default]
id_provider = ldap
auth_provider = ldap
sudo_provider = ldap
chpass_provider = none

ldap_id_use_start_tls = False

ldap_uri = ldaps://ldap1.sayakek.internal/ , ldaps://ldap2.sayakek.internal/
ldap_search_base = ou=users,ou=sayakekOU,dc=sayakek,dc=internal
ldap_group_search_base = ou=groups,ou=sayakekOU,dc=sayakek,dc=internal
ldap_group_object_class = x-customGroupAuxiliary

ldap_default_bind_dn = cn=sssdReadUser,ou=administrationUsers,dc=sayakek,dc=internal
ldap_default_authtok_type = password
ldap_default_authtok = <パスワード>

cache_credentials = True

access_provider = simple
simple_allow_groups = adminGroup

ldap_user_ssh_public_key = sshPublicKey

ldap_sudo_search_base = ou=Sudoers,dc=sayakek,dc=internal

[nss]
override_shell = /bin/bash

以下を実行後、sssd.confを開いて以下の部分だけをコピーし、上記のsssd.confの該当部分に上書きしたものを保存します。

# sss_obfuscate --domain=default
/etc/sssd/sssd.conf
ldap_default_authtok_type = obfuscated_password
ldap_default_authtok = <難読化パスワード>

権限を変更します。

# chmod 600 /etc/sssd/sssd.conf

sshdの設定を変更して、公開鍵認証が使えるようにします。

/etc/ssh/sshd_config
AuthorizedKeysCommand /usr/bin/sss_ssh_authorizedkeys
AuthorizedKeysCommandUser root

サービスを再起動します。

# systemctl restart sssd oddjobd sshd
# systemctl enable sssd oddjobd

パスワードレスsudo

以下を先頭に追加します。
これにより、SSH公開鍵認証 + エージェント転送を使用している環境でパスワードなしでsudoが可能になります。
パスワードを強制したい場合はこれを追加しないようにします。

/etc/pam.d/sudo
+ auth sufficient pam_ssh_agent_auth.so authorized_keys_command=/usr/bin/sss_ssh_authorizedkeys
/etc/pam.d/sudo-i
+ auth sufficient pam_ssh_agent_auth.so authorized_keys_command=/usr/bin/sss_ssh_authorizedkeys

確認

userDはadminGroupのユーザーなので、ログインとsudoが可能です。
image.png

ssh -l userD 172.16.1.100
userD@172.16.1.100's password:
Creating directory '/home/userD'.
Linux pvetest 7.0.12-1-pve #1 SMP PREEMPT_DYNAMIC PMX 7.0.12-1 (2026-06-09T21:07Z) x86_64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
$ sudo -l
[sudo] password for userD:
Matching Defaults entries for userD on pvetest:
    env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin, use_pty,
    !visiblepw, always_set_home, match_group_by_gid, always_query_group_plugin, env_reset, env_keep="COLORS DISPLAY
    HOSTNAME HISTSIZE KDEDIR LS_COLORS SSH_AUTH_SOCK MAIL PS1 PS2 QTDIR USERNAME LANG LC_ADDRESS LC_CTYPE LC_COLLATE
    LC_IDENTIFICATION LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE LC_TIME LC_ALL
    LANGUAGE LINGUAS _XKB_CHARSET XAUTHORITY", secure_path=/sbin\:/bin\:/usr/sbin\:/usr/bin

User userD may run the following commands on pvetest:
    (root) ALL

userAは設定どおり両方が不可能です。
image.png

ssh -l userA 172.16.1.100
userA@172.16.1.100's password:
Connection closed by 172.16.1.100 port 22
$ sudo -l -U userA
User userA is not allowed to run sudo on pvetest.

公開鍵ログインも動作します。

ssh -l userC 172.16.1.100
Creating directory '/home/userC'.
Linux pvetest 7.0.12-1-pve #1 SMP PREEMPT_DYNAMIC PMX 7.0.12-1 (2026-06-09T21:07Z) x86_64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.

おまけ Web GUIでSSSD + LDAPのユーザーを使う

はじめに

以下記事のようにLDAPレルムを定義して同期すればLDAPサーバー上のユーザーを使用することができます。
この記事のようにする必要性はほぼないと思われます。

設定

上記のようにSSSDを構成すると、SSHログインやsudoなどでLDAPサーバー上のユーザー情報を用いることができますが、Web GUIはレルムpamにユーザーが存在しなければ使えません。
image.png
image.png
一つ一つ手動でレルムpamにユーザーを追加するのも手ですが、今回はスクリプトとsystemd-timerを用いてこれを自動化します。
まず最初に、LDAPサーバーにスクリプトで使用するユーザーエントリを追加します。

dn: cn=pvePamReadUser,ou=administrationUsers,dc=sayakek,dc=internal
changetype: add
cn: pvePamReadUser
sn: pvePamReadUser
userPassword: <パスワード>
objectclass: top
objectclass: Person

このユーザーに対して、必要な権限を与えます。

ldap1.sayakek.internal用
dn: olcDatabase={2}mdb,cn=config
changetype: modify
delete: olcAccess
olcAccess: {2}to dn.subtree="ou=users,ou=sayakekOU,dc=sayakek,dc=internal" 
 by dn="cn=editUser,ou=providerUsers,ou=administrationUsers,dc=sayakek,dc=internal" write 
 by dn="cn=replicateUser,ou=providerUsers,ou=administrationUsers,dc=sayakek,dc=internal" read 
 by dn="cn=sssdReadUser,ou=administrationUsers,dc=sayakek,dc=internal" read 
 by self read 
 by * none
-
add: olcAccess
olcAccess: {2}to dn.subtree="ou=users,ou=sayakekOU,dc=sayakek,dc=internal" 
 by dn="cn=editUser,ou=providerUsers,ou=administrationUsers,dc=sayakek,dc=internal" write 
 by dn="cn=replicateUser,ou=providerUsers,ou=administrationUsers,dc=sayakek,dc=internal" read 
 by dn="cn=sssdReadUser,ou=administrationUsers,dc=sayakek,dc=internal" read 
 by dn="cn=pvePamReadUser,ou=administrationUsers,dc=sayakek,dc=internal" read 
 by self read 
 by * none
ldap2.sayakek.internal用
dn: olcDatabase={2}mdb,cn=config
changetype: modify
delete: olcAccess
olcAccess: {0}to attrs=userPassword 
 by anonymous auth 
 by * none
olcAccess: to dn.subtree="ou=users,ou=sayakekOU,dc=sayakek,dc=internal" 
 by dn="cn=sssdReadUser,ou=administrationUsers,dc=sayakek,dc=internal" read 
 by * none
-
add: olcAccess
olcAccess: {0}to attrs=userPassword 
 by dn="cn=radiusReadUser,ou=administrationUsers,dc=sayakek,dc=internal" read 
 by anonymous auth 
 by * none
olcAccess: {1}to dn.subtree="ou=users,ou=sayakekOU,dc=sayakek,dc=internal" 
 by dn="cn=sssdReadUser,ou=administrationUsers,dc=sayakek,dc=internal" read 
 by dn="cn=pvePamReadUser,ou=administrationUsers,dc=sayakek,dc=internal" read 
 by * none

スクリプト類を格納するディレクトリを作成します。

$ sudo mkdir -p /usr/local/pvepamutils/tmp
$ sudo chmod -R 600 /usr/local/pvepamutils/

以下のスクリプトを作成します。
LDAPサーバーから取得したgidNumberが4000のユーザーのリストを前回取得時のリストと比較し、差分が出たら文字列を整形してAPIに投げ、ユーザーのレルムおよびグループへの追加・削除を行うという内容になります。
このスクリプト以外からのユーザーの追加・削除・変更は想定していませんが、ユーザーを先に検索して戻り値によって追加・削除するようにしてもいいかもしれません。

/usr/local/pvepamutils/syncpamfromLdap.sh
#!/bin/bash

set -eu

readonly ldapsv="ldaps://ldap1.sayakek.internal/,ldaps://ldap2.sayakek.internal/"
readonly binddn=cn=pvePamReadUser,ou=administrationUsers,dc=sayakek,dc=internal
readonly password=<pvePamReadUserのパスワード>
readonly userdn=ou=users,ou=sayakekOU,dc=sayakek,dc=internal
readonly condition=gidNumber=4000
readonly searchattr=dn
readonly adminlist=/usr/local/pvepamutils/tmp/adminlist
readonly oldadminlist=/usr/local/pvepamutils/tmp/adminlist.old
readonly dellist=/usr/local/pvepamutils/tmp/deluserlist
readonly addlist=/usr/local/pvepamutils/tmp/adduserlist
readonly groupname=admins

if [ ! -e $oldadminlist ]; then
        touch $oldadminlist
else
        mv $adminlist $oldadminlist
fi

ldapsearch -H $ldapsv -D $binddn -w $password -b $userdn $condition $searchattr -LLL  | awk -F ',' '{if ( $1 != "") {print $1}}' | sed -e 's/^dn: cn=//' -e 's/$/@pam/' > $adminlist

diff $adminlist $oldadminlist | grep ">" | sed 's/> //' > $dellist
diff $adminlist $oldadminlist | grep "<" | sed 's/< //' > $addlist

if [ -s $dellist ]; then
        cat $dellist | while read userid
        do
                pvesh delete /access/users/$userid
        done
fi

if [ -s $addlist ]; then
        cat $addlist | while read userid
        do
                pvesh create /access/users --userid $userid --groups $groupname
        done
fi

権限を調整します。

$ sudo chmod 500 /usr/local/pvepamutils/syncpamfromLdap.sh

グループ「admins」を作成して、適切な権限を割り当てます。
image.png
image.png
作成したシェルスクリプトが定期的に動作するようにsystemd.timerを定義します。

/etc/systemd/system/syncpamfromLdap.service
[Unit]
Description="Sync PAM user from LDAP"

[Service]
ExecStart=/bin/bash /usr/local/pvepamutils/syncpamfromLdap.sh
/etc/systemd/system/syncpamfromLdap.timer
[Unit]
Description="Run syncpamfromLdap.service 5 min after boot and every minute"

[Timer]
OnStartupSec=5min
OnUnitActiveSec=5min

[Install]
WantedBy=timers.target

systemd-timerを有効にします。

$ sudo systemctl daemon-reload
$ sudo systemctl enable syncpamfromLdap.timer --now

レルム PAMにユーザーが追加されると、そのユーザーを使ってSSSD経由でのWeb GUIアクセスが可能になります。
image.png
image.png
ユーザーのgidNumberを変更した後、スクリプトが実行されると正しくユーザーの追加と削除が実行されます。
image.png
image.png
image.png

参考文献

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?