環境
Ubuntu 26.04 LTS
前提
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/local/share/ca-certificates/以下にコピーし、次のコマンドを実行します。
$ sudo chown root:root /usr/local/share/ca-certificates/ca_cert.crt
$ sudo update-ca-certificates
インストール
まず最初に、sudo-rsからレガシーsudoに変更します。
sudo-rsには、LDAPサーバー上のsudoersを使用する機能が存在しないためです。(私はこれで半日無駄にしました)
$ sudo update-alternatives --set sudo /usr/bin/sudo.ws
次に先んじてnsswitch.confを作成します。パッケージのインストールによってsudoers: sssが自動的に書き込まれ、ローカルユーザーでのsudoが実行できなくなることを防ぎます。
# /etc/nsswitch.conf
#
# Example configuration of GNU Name Service Switch functionality.
# If you have the `glibc-doc-reference' and `info' packages installed, try:
# `info libc "Name Service Switch"' for information about this file.
passwd: files systemd sss
group: files systemd sss
shadow: files systemd sss
gshadow: files systemd
hosts: files dns
networks: files
protocols: db files
services: db files sss
ethers: db files
rpc: db files
netgroup: nis sss
sudoers: files sss
automount: files sss
必要なパッケージをインストールします。
パスワードレスsudoが必要であればlibpam-ssh-agent-authもインストールします。
ホームディレクトリの自動作成も有効にします。
$ sudo apt install libsss-sudo sssd sssd-tools oddjob-mkhomedir
$ sudo pam-auth-update --enable mkhomedir
以下の定義ファイルを作成します。
[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
サービスを再起動します。
$ sudo systemctl restart sssd oddjobd sshd
$ sudo systemctl enable sssd oddjobd
パスワードレスsudo
以下を先頭に追加します。
これにより、SSH公開鍵認証 + エージェント転送を使用している環境でパスワードなしでsudoが可能になります。
パスワードを強制したい場合はこれを追加しないようにします。
+ auth sufficient pam_ssh_agent_auth.so authorized_keys_command=/usr/bin/sss_ssh_authorizedkeys
+ auth sufficient pam_ssh_agent_auth.so authorized_keys_command=/usr/bin/sss_ssh_authorizedkeys
確認
まずはパスワードログインを確認しましょう。

正常にログインできました。
ホームディレクトリの自動作成、sudoの実行も確認できます。
ssh -l userA 172.16.1.90
userA@172.16.1.90's password:
Creating directory '/home/userA'.
Welcome to Ubuntu 26.04 LTS (GNU/Linux 7.0.0-22-generic x86_64)
* Documentation: https://docs.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/pro
This system has been minimized by removing packages and content that are
not required on a system that users do not log into.
To restore this content, you can run the 'unminimize' command.
The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.
$ sudo cat /etc/os-release
[sudo] password for userA:
PRETTY_NAME="Ubuntu 26.04 LTS"
NAME="Ubuntu"
VERSION_ID="26.04"
VERSION="26.04 LTS (Resolute Raccoon)"
VERSION_CODENAME=resolute
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=resolute
LOGO=ubuntu-logo
ユーザーグループのユーザーで確認します。

正しく拒否されました。
ssh -l userB 172.16.1.90
userB@172.16.1.90's password:
Connection closed by 172.16.1.90 port 22
userGroupなのでsudoもできません。
$ sudo -l -U userB
User userB is not allowed to run sudo on ca.
ssh -l userB 172.16.1.90
userB@172.16.1.90's password:
Creating directory '/home/userB'.
Welcome to Ubuntu 26.04 LTS (GNU/Linux 7.0.0-22-generic x86_64)
* Documentation: https://docs.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/pro
This system has been minimized by removing packages and content that are
not required on a system that users do not log into.
To restore this content, you can run the 'unminimize' command.
The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.
$ sudo cat /etc/os-release
[sudo] password for userB:
PRETTY_NAME="Ubuntu 26.04 LTS"
NAME="Ubuntu"
VERSION_ID="26.04"
VERSION="26.04 LTS (Resolute Raccoon)"
VERSION_CODENAME=resolute
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=resolute
LOGO=ubuntu-logo
公開鍵ログインもできます。
ssh -l userC 172.16.1.90
Creating directory '/home/userC'.
Welcome to Ubuntu 26.04 LTS (GNU/Linux 7.0.0-22-generic x86_64)
* Documentation: https://docs.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/pro
This system has been minimized by removing packages and content that are
not required on a system that users do not log into.
To restore this content, you can run the 'unminimize' command.
The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.
パスワードレスsudoの確認
SSHエージェント転送を有効にして接続すると、パスワードレスsudoが実現できます。
ssh -A -l userC 172.16.1.90
Welcome to Ubuntu 26.04 LTS (GNU/Linux 7.0.0-22-generic x86_64)
* Documentation: https://docs.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/pro
This system has been minimized by removing packages and content that are
not required on a system that users do not log into.
To restore this content, you can run the 'unminimize' command.
Last login: Wed Jun 24 09:32:40 2026 from 192.168.0.210
$ sudo cat /etc/os-release
PRETTY_NAME="Ubuntu 26.04 LTS"
NAME="Ubuntu"
VERSION_ID="26.04"
VERSION="26.04 LTS (Resolute Raccoon)"
VERSION_CODENAME=resolute
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=resolute
LOGO=ubuntu-logo
$ sudo -i
#
