LDAP サーバーを構築・設定して、各サーバー間でユーザーのアカウント情報を共有出来るようにします。
Unix アカウント・メールアカウント・FTPアカウント・SASL認証(SMTP認証)・Samba アカウント等を一元化して管理します。
LDAP サーバーの構築・設定方法
[root@server1 ~]# dnf –enablerepo=epel -y install openldap-servers openldap-clients ← OpenLDAPのサーバーとクライアントをインストールします。
[root@server1 ~]# systemctl enable slapd ← OpenLDAPが自動的に起動するように設定します。
[root@server1 ~]# slappasswd ← 管理者のパスワードを生成します。
New password:
Re-enter new password:
{SSHA}xxxxxxxxxxxxxxxxxxxxxxxx
[root@server1 ~]# vi chrootpw.ldif
dn: olcDatabase={0}config,cn=config
changetype: modify
add: olcRootPW
olcRootPW: {SSHA}xxxxxxxxxxxxxxxxxxxxxxxx ← olcRootPW に生成した管理者のパスワードを指定します。
[root@server1 ~]# ldapadd -Y EXTERNAL -H ldapi:/// -f chrootpw.ldif
SASL/EXTERNAL authentication started
SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth
SASL SSF: 0
modifying entry “olcDatabase={0}config,cn=config”
基本的なスキーマを読み込みます。
[root@server1 ~]# ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/cosine.ldif
SASL/EXTERNAL authentication started
SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth
SASL SSF: 0
adding new entry “cn=cosine,cn=schema,cn=config”
[root@server1 ~]# ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/nis.ldif
SASL/EXTERNAL authentication started
SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth
SASL SSF: 0
adding new entry “cn=nis,cn=schema,cn=config”
[root@server1 ~]# ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/inetorgperson.ldif
SASL/EXTERNAL authentication started
SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth
SASL SSF: 0
adding new entry “cn=inetorgperson,cn=schema,cn=config”
[root@server1 ~]# slappasswd ← ディレクトリマネージャーのパスワードを生成します。
New password:
Re-enter new password:
{SSHA}xxxxxxxxxxxxxxxxxxxxxxxx
[root@server1 ~]# vi chdomain.ldif
[dc=***,dc=***] は自身のドメイン名に置き換えてください。 olcRootPW に生成したディレクトリマネージャーのパスワードを指定して下さい。
dn: olcDatabase={1}monitor,cn=config changetype: modify replace: olcAccess olcAccess: {0}to * by dn.base="gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth" read by dn.base="cn=Manager,dc=zoah,dc=lan" read by * none dn: olcDatabase={2}mdb,cn=config changetype: modify replace: olcSuffix olcSuffix: dc=zoah,dc=lan dn: olcDatabase={2}mdb,cn=config changetype: modify replace: olcRootDN olcRootDN: cn=Manager,dc=zoah,dc=lan dn: olcDatabase={2}mdb,cn=config changetype: modify add: olcRootPW olcRootPW: {SSHA}xxxxxxxxxxxxxxxxxxxxxxxx dn: olcDatabase={2}mdb,cn=config changetype: modify add: olcAccess olcAccess: {0}to attrs=userPassword,shadowLastChange by dn="cn=Manager,dc=zoah,dc=lan" write by anonymous auth by self write by * none olcAccess: {1}to dn.base="" by * read olcAccess: {2}to * by dn="cn=Manager,dc=zoah,dc=lan" write by * read
[root@server1 ~]# ldapmodify -Y EXTERNAL -H ldapi:/// -f chdomain.ldif
SASL/EXTERNAL authentication started
SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth
SASL SSF: 0
modifying entry “olcDatabase={1}monitor,cn=config”
modifying entry “olcDatabase={2}mdb,cn=config”
modifying entry “olcDatabase={2}mdb,cn=config”
modifying entry “olcDatabase={2}mdb,cn=config”
modifying entry “olcDatabase={2}mdb,cn=config”
[root@server1 ~]# vi basedomain.ldif
dc=***,dc=*** は自身のドメイン名に置き換えて下さい。
dn: dc=zoah,dc=lan objectClass: top objectClass: dcObject objectclass: organization o: zoah.net dc: zoah dn: cn=Manager,dc=zoah,dc=lan objectClass: organizationalRole cn: Manager description: Directory Manager dn: ou=People,dc=zoah,dc=lan objectClass: organizationalUnit ou: People dn: ou=Group,dc=zoah,dc=lan objectClass: organizationalUnit ou: Group
[root@server1 ~]# ldapadd -x -D cn=Manager,dc=zoah,dc=lan -W -f basedomain.ldif
Enter LDAP Password: ← ディレクトリマネージャーのパスワードを入力して下さい。
adding new entry “dc=zoah,dc=lan”
adding new entry “cn=Manager,dc=zoah,dc=lan”
adding new entry “ou=People,dc=zoah,dc=lan”
adding new entry “ou=Group,dc=zoah,dc=lan”
次に、samba スキーマを ldap-server に搭載します。
[root@server1 ~]# cp /usr/share/doc/samba/LDAP/samba.ldif /root/
[root@server1 ~]# ldapadd -Y EXTERNAL -H ldapi:/// -f /root/samba.ldif
SASL/EXTERNAL authentication started
SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth
SASL SSF: 0
adding new entry “cn=samba,cn=schema,cn=config”
SSL/TLS を設定します。ここでは自己署名の証明書を作成して進めます。
[root@server1 ~]# vi /etc/ssl/openssl.cnf
最終行に追記して下さい。
セクション名は任意です。
DNS:(自身のホスト名)
DNS を複数指定する場合はカンマ区切りです。
[ zoah.lan ]
subjectAltName = DNS:server1.zoah.lan
[root@server1 ~]# cd /etc/pki/tls/certs
[root@server1 certs]# openssl genrsa -aes256 2048 > server.key
Enter PEM pass phrase: ← パスフレーズを設定して下さい。
Verifying – Enter PEM pass phrase: ← 再入力して下さい。
[root@server1 certs]# openssl rsa -in server.key -out server.key ← 秘密鍵からパスフレーズを削除します。
Enter pass phrase for server.key: ← パスフレーズを入力して下さい。
writing RSA key
[root@server1 certs]# openssl req -utf8 -new -key server.key -out server.csr
You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [XX]:JP # 国 State or Province Name (full name) []:Wakayama # 地域(県) Locality Name (eg, city) [Default City]:Iwade # 都市 Organization Name (eg, company) [Default Company Ltd]:zoah.lan # 組織名 Organizational Unit Name (eg, section) []:zoah.lan # 組織の部門名 Common Name (eg, your name or your server's hostname) []:server1.zoah.lan # サーバーの FQDN Email Address []:test@zoah.net # 管理者アドレス Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: An optional company name []:
[root@server1 certs]# openssl x509 -in server.csr -out server.crt -req -signkey server.key -extfile /etc/ssl/openssl.cnf -extensions zoah.lan -days 3650
↑ 有効期限が10年の自己署名証明書を作成します。-extensions(セクション名) → [openssl.cnf] に追記したセクション名です。
[root@server1 certs]# chmod 600 server.key
[root@server1 ~]# cp /etc/pki/tls/certs/{server.key,server.crt} /etc/openldap/certs/
[root@server1 ~]# chown ldap:ldap /etc/openldap/certs/{server.key,server.crt}
[root@server1 ~]# vi mod_ssl.ldif
dn: cn=config changetype: modify replace: olcTLSCertificateFile olcTLSCertificateFile: /etc/openldap/certs/server.crt - replace: olcTLSCertificateKeyFile olcTLSCertificateKeyFile: /etc/openldap/certs/server.key
[root@server1 ~]# ldapmodify -Y EXTERNAL -H ldapi:/// -f mod_ssl.ldif
SASL/EXTERNAL authentication started
SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth
SASL SSF: 0
modifying entry “cn=config”
URIをldaps://を指定することで,通信の暗号化を強制出来ます。
ldaps:// 接続を有効化する為に、/etc/default/slapdを次のように書き換えます。
- SLAPD_SERVICES="ldap:/// ldapi:///" + SLAPD_SERVICES="ldap:/// ldapi:/// ldaps:///"
[root@server1 ~]# systemctl restart slapd ← OpenLDAPを再起動します。
[root@server1 ~]# systemctl enable slapd ← OpenLDAPを自動的に起動するように設定します。
ファイルディスクリプタ上限値の設定
LDAPはセッション数が多い為、入出力を管理するファイルディスクリプタ数が足りなくなることがあります。環境によっては変更しておいたほうが良いです。
[root@server1 ~]# vi /usr/lib/systemd/system/slapd.service
[Service] の箇所の一番下に追加します。
---ここから--- LimitNOFILE=65536 LimitNPROC=65536 ---ここまで---
[root@server1 ~]# systemctl daemon-reload ← デーモンを読み込みます。
[root@server1 ~]# systemctl restart slapd ← OpenLDAPを再起動します。
LDAP クライアントの設定方法
自己証明書を使用する場合、下記エラーが発生します。
ldap_sasl_bind(SIMPLE): Can’t contact LDAP server (-1)
エラー回避のために、 /etc/openldap/ldap.conf に下記設定を追加します。
TLS_REQCERT never
/etc/openldap/ldap.conf を下記のように編集します。
# # LDAP Defaults # # See ldap.conf(5) for details # This file should be world readable but not world writable. #BASE dc=example,dc=com #URI ldap://ldap.example.com ldap://ldap-master.example.com:666 #SIZELIMIT 12 #TIMELIMIT 15 #DEREF never # When no CA certificates are specified the Shared System Certificates # are in use. In order to have these available along with the ones specified # by TLS_CACERTDIR one has to include them explicitly: #TLS_CACERT /etc/pki/tls/cert.pem TLS_CACERTDIR /etc/openldap/certs/ TLS_REQCERT never # System-wide Crypto Policies provide up to date cipher suite which should # be used unless one needs a finer grinded selection of ciphers. Hence, the # PROFILE=SYSTEM value represents the default behavior which is in place # when no explicit setting is used. (see openssl-ciphers(1) for more info) #TLS_CIPHER_SUITE PROFILE=SYSTEM # Turning this off breaks GSSAPI used with krb5 when rdns = false SASL_NOCANON on #URI 192.168.100.200 URI ldaps://server1.zoah.lan ← LDAPサーバーを指定します。 BASE dc=zoah,dc=lan ← 各自の環境に合わせて設定して下さい。
[root@server1 ~]# dnf -y install openldap-clients sssd sssd-ldap oddjob-mkhomedir ← OpenLDAP クライアントをインストールして設定します。
[root@server1 ~]# authselect select sssd with-mkhomedir --force ← 認証プロバイダーを sssd に切り替え、初回ログイン時にホームディレクトリを自動生成します。
Backup stored at /var/lib/authselect/backups/2022-03-23-05-13-41.enGlNB Profile "sssd" was selected. The following nsswitch maps are overwritten by the profile: - passwd - group - netgroup - automount - services Make sure that SSSD service is configured and enabled. See SSSD documentation for more information. - with-mkhomedir is selected, make sure pam_oddjob_mkhomedir module is present and oddjobd service is enabled and active - systemctl enable --now oddjobd.service
[root@server1 ~]# vi /etc/sssd/sssd.conf
[domain/default] id_provider = ldap autofs_provider = ldap auth_provider = ldap chpass_provider = ldap ldap_uri = ldaps://server1.zoah.lan/ ← 各自の環境に合わせて設定して下さい。 ldap_search_base = dc=zoah,dc=lan ← 各自の環境に合わせて設定して下さい。 ldap_id_use_start_tls = True ldap_tls_cacertdir = /etc/openldap/certs cache_credentials = True ldap_tls_reqcert = never ← 自己証明書を使用している為、neverを設定します。 ldap_default_bind_dn = cn=Manager,dc=zoah,dc=lan ← 各自の環境に合わせて設定して下さい。 ldap_default_authtok = ディレクトリマネージャーのパスワード [sssd] services = nss, pam, autofs domains = default [nss] homedir_substring = /home #filter_groups = root ← 行頭に#を追加して、コメントアウトします。 #filter_users = root ← 行頭に#を追加して、コメントアウトします。 reconnection_retries = 3 entry_cache_timeout = 60 [pam] reconnection_retries = 3
[root@server1 ~]# chmod 600 /etc/sssd/sssd.conf
[root@server1 ~]# systemctl restart sssd oddjobd ← sssd と oddjobd を再起動します。
[root@server1 ~]# systemctl enable sssd oddjobd ← sssd と oddjobd を自動的に起動するように設定します。