LoginSignup
0
0

More than 1 year has passed since last update.

Ubuntu20.04 で OpenLDAP サーバを構築してみる

Posted at

本記事の目的

Ubuntu 20.04 上に OpenLDAP を構築してその動作確認をおこなったので、整理目的で記事投稿。
目指すところは・・・以下のように、LDAP サーバーにおける登録情報を元に、LDAP クライアントにログインできるようにしたい。

environment.png

LDAP の構成は以下のようになる。

ldap.png

なお、手順については以下を参照させていただいてます。

LDAP サーバー・クライアントともに、環境は以下の通り。

$ lsb_release -a

Distributor ID: Ubuntu
Description:    Ubuntu 20.04.5 LTS
Release:        20.04
Codename:       focal

手順

LDAP サーバーでの手順

  • slapd と ldap-utils をインストール
$ sudo apt install -y slapd ldap-utils
  • ドメイン名等を設定する。
    • ここではドメイン名を hoge.example.com、組織名を hoge としておく。
$ sudo dpkg-reconfigure slapd

Omit OpenLDAP server configuration?: No

DNS domain name?: hoge.example.com

Organization name?: hoge

Administrator password?: [管理者パスワード(インストール時に設定したものを再設定)]
  • グループの追加
    • 以下の内容を記載のうえ、base.ldif ファイルを作成する。
$ cd /etc/ldap/
$ sudo nano base.ldif

---以下、base.ldif の内容---
dn: ou=people,dc=hoge,dc=example,dc=com
objectClass: organizationalUnit
ou: people
  • 以下コマンドにて設定を追加する
 $ ldapadd -x -D cn=admin,dc=hoge,dc=example,dc=com -W -f base.ldif

<想定出力結果>
Enter LDAP Password:
adding new entry "ou=people,dc=hoge,dc=example,dc=com"
  • ユーザ用のパスワードを生成する
    • パスワードは平文ではなくハッシュ値にてファイルに記載する。パスワードのハッシュ値を生成するためのコマンドとして、slappasswd があるので活用させてもらう。
$ slappasswd
New password:
Re-enter new password:
{SSHA}xxxxxxxxxxxxxxxxxxxxxxx
  • ldapuser.ldif ファイルを作成する
    • userPassword については、前手順で作成した {SSHA}... ではじまる文字列を入力する
$ sudo nano ldapuser.ldif

---以下、ldapuser.ldif の内容---
dn: uid=user001,ou=people,dc=hoge,dc=example,dc=com
objectClass: inetOrgPerson
objectClass: posixAccount
objectClass: shadowAccount
cn: user001
sn: user001
userPassword: {SSHA}xxxxxxxxxxxxxxxxxxxxxxx
loginShell: /bin/bash
uidNumber: 2000
gidNumber: 2000
homeDirectory: /home/user001

dn: cn=user001,ou=groups,dc=hoge,dc=example,dc=com
objectClass: posixGroup
cn: ubuntu
gidNumber: 2000
memberUid: user001
  • 設定の追加
$ ldapadd -x -D cn=admin,dc=hoge,dc=example,dc=com -W -f ldapuser.ldif

<想定出力結果>
Enter LDAP Password:
adding new entry "uid=user001,ou=people,dc=hoge,dc=example,dc=com"

adding new entry "cn=user001,ou=groups,dc=hoge,dc=example,dc=com"

LDAP クライアントでの手順

  • LDAP クライアントのインストール
$ sudo apt install -y libnss-ldapd libpam-ldapd ldap-utils

インストール時の質問は以下の通り回答

LDAP server Uniform Resource Identifier: ldap://192.168.56.102 # 構築した LDAP サーバーの IP アドレス

Distinguished name of the search base: dc=hoge,dc=example,dc=com

Name services to configure: [passwd, group, shadow をチェック]
  • ログイン時に自動でホームディレクトリが作成されるよう、以下を追記する。
$ sudo nano /etc/pam.d/common-session 

# 最終行に以下を追記
session optional        pam_mkhomedir.so skel=/etc/skel umask=077

※ 参考

  • 最後に再起動
$ sudo reboot

動作確認

user001 で LDAP クライアントにログインできるかを確認する。

 ssh user001@192.168.56.101

うまくいってれば以下みたいにログインできる。
※ group ID でエラー出てしまっているが、LDAP の動作確認としては十分と考えここではスルーさせていただきます。。

Creating directory '/home/user001'.
Welcome to Ubuntu 20.04.5 LTS (GNU/Linux 5.15.0-56-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

115 updates can be applied immediately.
85 of these updates are standard security updates.
To see these additional updates run: apt list --upgradable

New release '22.04.1 LTS' available.
Run 'do-release-upgrade' to upgrade to it.

Your Hardware Enablement Stack (HWE) is supported until April 2025.

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.

groups: cannot find name for group ID 2000
user001@xxxxxx:~$
0
0
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
0