ユーザ用ツール

LDAP

概要

LAN内のユーザアカウントとメールアカウントを管理するケースについて OpenLDAP サーバの設定および、クライアントの設定についてまとめる。

なお、メールは Postfix + dovecot でSMTPおよびIMAPサービスを行うものとする。

サーバ

クライアント

SSSD

今時のクライアントサイドはSSSDを使うものだ、と、AIが言うので、SSSDで設定を行うことにしたら、NSLCDよりよほど簡単だった。

モジュール

sssd, libnss-sss, libpam-sss, および ldap-utils をインストールしておく。

$ sudo apt install -y sssd libnss-sss libpam-sss ldap-utils

sssd.conf

SSSDをインストールしても sssd.confのひな形が作られたりはしないので、自分で全部書く。 /etc/sssd/sssd.conf は、そんなにたくさん書かなくても動くのでそれほど心配しなくてもいい。

sssd.conf
[sssd]
service = nss, pam
config_file_version = 2
domains = exmaple.com
 
[domain/example.com]
id_provider = ldap
auth_provider = ldap
 
ldap_uri = ldaps://ldap.example.com
ldap_search_base = dc=example,dc=com
 
ldap_default_bind_dn = cn=admin,dc=example,dc=com
ldap_default_authok = password
 
cache_credentials = True
enumerate = True

[sssd]セクションでは domainsで指定するが、ドメインを各セクションは [domain/<ドメイン名>]になるので間違えないように気をつける。

当然、ドメイン名やdcなどについては自分のものに置き換えること。 設定ファイルを保存したら、sssdを再起動する。

$ sudo systemctl restart sssd.service

基本的に nsswitch.confなどはいじらないでも sss が追加されている。 もし /etc/passwdや /etc/group にLDAPと衝突する設定があるなら適宜修正しておく。

LDAPユーザがログインしたときに、自動的にホームディレクトリを作成させたいなら、以下のように /etc/pam.d/common-sessionに追記しておくといい。

common-session
session	required	pam_mkhomedir.so	skel=/etc/skel	umask=0022

きちんとLDAPからエントリを読み込んでいるかどうかは、getentなどで確かめればいい。

$ getent passwd

正しく読めていれば、LDAPに設定されているユーザのエントリーが /etc/passwdに加えて表示されるはずである。

NSLCD

伝統的には、クライアント側では NSLCDを使用することが一般的であった。

モジュール

設定

基本的には設定はパッケージのpost installation ステップで行われるので、nslcd.confを直接いじる必要はほとんどないと思われるが、何かあればここをいじることになる。

nslcd.conf
# /etc/nslcd.conf
# nslcd configuration file. See nslcd.conf(5)
# for details.
 
# The user and group nslcd should run as.
uid nslcd
gid nslcd
 
# The location at which the LDAP server(s) should be reachable.
uri ldaps://ldap.example.com ldap://192.168.10.1 ldap://192.168.10.2
 
# The search base that will be used for all queries.
base dc=example,dc=com
 
# The LDAP protocol version to use.
#ldap_version 3
 
# The DN to bind with for normal lookups.
#binddn cn=annonymous,dc=example,dc=net
#bindpw secret
 
# The DN used for password modifications by root.
#rootpwmoddn cn=admin,dc=example,dc=com
 
# SSL options
#ssl off
#tls_reqcert never
tls_cacertfile /etc/ssl/certs/ca-certificates.crt
 
# The search scope.
#scope sub

/etc/nsswitch.conf については sssd の場合と同じで、基本的には必要な場所に ldapが追加されているので、特別に何かを追加したいのでなければほっておいて構わない。

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also, you acknowledge that you have read and understand our Privacy Policy. If you do not agree, please leave the website.

More information