環境
AlmaLinux 10.2
前提
LDAPサーバーに以下のエントリが追加されている必要があります。
adminGroupに所属のユーザーがsudoを実行できるような設定です。
ldapadd -D 'cn=editUser,ou=providerUsers,ou=administrationUsers,dc=sayakek,dc=internal' -Wなどで追加します。
dn: cn=<サーバーホスト名>,ou=sudoers,dc=sayakek,dc=internal
objectClass: sudoRole
cn: <サーバーホスト名>
sudoHost: <サーバーホスト名>
sudoCommand: ALL
sudoUser: %adminGroup
サーバーにはホスト名が設定されている必要があります。
以下ではFQDNを設定していますが、必ずしもFQDNである必要はありません。また、必ずしも解決可能なホスト名である必要はありません。
$ sudo hostnamectl set-hostname <サーバーホスト名>.sayakek.internal
CA証明書もインストールされている必要があります。
ca_cert.crtを/usr/share/pki/ca-trust-source/anchors/以下にコピーし、次のコマンドを実行します。
$ sudo chown root:root /usr/share/pki/ca-trust-source/anchors/ca_cert.crt
$ sudo restorecon /usr/share/pki/ca-trust-source/anchors/ca_cert.crt
$ sudo update-ca-trust extract
インストール
RHEL10からパスワードレスsudoに使用するpam_ssh_agent_authが廃止されました。
代替として、pam_ssh_agentとpam_rsshが提唱されていますが、いずれもまだ標準のリポジトリから入手できるものではありません。
必要なパッケージをインストールして、ホームディレクトリを自動作成する設定をします。
$ sudo dnf install openldap-clients sssd sssd-ldap sssd-tools oddjob-mkhomedir
$ sudo authselect select sssd with-mkhomedir --force
ファイル最後尾に以下を追加します。
(前略)
networks: files dns
protocols: files
publickey: files
rpc: files
+ sudoers: files sss
以下の定義ファイルを作成します。
ID、認証、sudoでLDAPを参照します。
adminGroupのユーザーがログインできる設定です。
[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
以下を実行します。
$ sudo sss_obfuscate --domain=default
実行後、sssd.confを開いて以下の部分だけをコピーし、上記のsssd.confの該当部分に上書きしたものを保存します。(上記コマンドにより内容がパスワード以外の内容も書き換わってしまうため)
ldap_default_authtok_type = obfuscated_password
ldap_default_authtok = <難読化パスワード>
権限を変更します。
$ sudo chmod 600 /etc/sssd/sssd.conf
sshdの設定を変更して、公開鍵認証が使えるようにします。
AuthorizedKeysCommand /usr/bin/sss_ssh_authorizedkeys
AuthorizedKeysCommandUser root
以下はRHEL10系では使えませんが、参考程度に紹介します。
pam_ssh_agent_authが使える環境で、パスワードレスsudoを使う場合は次の通りにします。
これにより、SSH公開鍵認証 + エージェント転送を使用している環境でパスワードなしでsudoが可能になります。
パスワードを強制したい場合はこれを追加しないようにします。
+ auth sufficient pam_ssh_agent_auth.so authorized_keys_command=/usr/bin/sss_ssh_authorizedkeys
サービスを再起動します。
$ sudo systemctl restart sssd oddjobd sshd
$ sudo systemctl enable sssd oddjobd
確認
まずはパスワードログインができるか確認します。


無事ログインできました。
ssh -l userA 172.16.1.11
The authenticity of host '172.16.1.11 (172.16.1.11)' can't be established.
ED25519 key fingerprint is SHA256:<sha256 hash>
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '172.16.1.11' (ED25519) to the list of known hosts.
userA@172.16.1.11's password:
[userA@dns ~]$
sudoも実行できます。
$ sudo cat /etc/redhat-release
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:
#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.
For security reasons, the password you type will not be visible.
[sudo] password for userA:
AlmaLinux release 10.2 (Lavender Lion)
ホームディレクトリの自動作成もできています。
$ pwd
/home/userA
userGroupのユーザーで試してみます。


期待した通り、ログインできません。
ssh -l userB 172.16.1.11
userB@172.16.1.11's password:
Connection closed by 172.16.1.11 port 22
userBがsudoできるか確認すると、期待通りできないようになっています。
$ sudo -l -U userB
User userB is not allowed to run sudo on dns.
adminGroupに変更します。


ログインとsudoができるようになりました。
ssh -l userB 172.16.1.11
userB@172.16.1.11's password:
Last failed login: Tue Jun 23 22:51:14 JST 2026 from 192.168.0.210 on ssh:notty
There was 1 failed login attempt since the last successful login.
[userB@dns ~]$ sudo cat /etc/redhat-release
AlmaLinux release 10.2 (Lavender Lion)
鍵ペアを作ってSSH公開鍵認証が使えるか確認します。
ssh-keygen -C userC
Generating public/private ed25519 key pair.
Enter file in which to save the key (C:\Users\admin/.ssh/id_ed25519): C:\temp\ssh_key
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in C:\temp\ssh_key
Your public key has been saved in C:\temp\ssh_key.pub
The key fingerprint is:
SHA256:Hz+9mcI277rGpHVp2vqgqlHXN0zyCi+DWfZHB42f62A userC
The key's randomart image is:
+--[ED25519 256]--+
| |
| o |
| . + .|
| . = o.|
| S * . *oo|
| . B *o=+o.|
| . o +*BEo. |
| . .+X+++ |
| .....o+XB. |
+----[SHA256]-----+
公開鍵でログインができました。(キャッシュが効いていない新規ユーザーで確認)
ssh-add C:\temp\ssh_key
Enter passphrase for C:\temp\ssh_key:
Identity added: C:\temp\ssh_key (userC)
ssh -A -l userC 172.16.1.11
[userC@dns ~]$
プロバイダー側停止時
一度もクライアントにログインしていないユーザーを用意します。

プロバイダー側のLDAPサーバーの通信を遮断して確認します。
$ sudo nmcli con down ens18
$ nmap -sV ldap1.sayakek.internal -p 636
Starting Nmap 7.98 ( https://nmap.org ) at 2026-06-24 18:46 +0900
Note: Host seems down. If it is really up, but blocking our ping probes, try -Pn
Nmap done: 1 IP address (0 hosts up) scanned in 3.65 seconds
SSHで接続を試行すると、正常に動作します。
sudoも問題ありません。
ssh -l userD 172.16.1.11
userD@172.16.1.11's password:
[userD@dns ~]$ sudo cat /etc/redhat-release
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:
#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.
For security reasons, the password you type will not be visible.
[sudo] password for userD:
AlmaLinux release 10.2 (Lavender Lion)
ldap2.sayakek.internalのslapd.logにも操作した時間にクライアントからの接続試行が記録されており、正しく動作していることがうかがえます。
Jun 24 18:48:07 localhost slapd[3779]: conn=1004 fd=18 ACCEPT from IP=172.16.1.11:51154 (IP=172.16.1.20:636)
