なみひらブログ

学んだことを日々記録する。~ since 2012/06/24 ~

CentOS 6.xのLDAP設定(クライアント)のメモ

サーバ情報

OS Cent OS 6.4(64bit)
スペック 4vCPU 8GBメモリ 100GBディスク

基本作業

ログインできることを確認する

login as: root
root@xx.xx.xx.xx's password:
Last login: Fri Dec 20 10:02:11 2013 from zz.zz.zz.zz

できた。

OSのバージョンを確認する

[root@xx.xx.xx.xx ~]# cat /etc/redhat-release
CentOS release 6.4 (Final)

ふむふむ(´・~・`)

プロキシの設定を行う

[root@xx.xx.xx.xx ~]# vi /etc/yum.conf
・・・
proxy=http://(サーバ):(ポート)
proxy_username=(ユーザ名)
proxy_password=(パスワード)
・・・

ソフトウェアを最新化する

[root@xx.xx.xx.xx ~]# yum update
・・・
Transaction Summary
================================================================================
Install      18 Package(s)
Upgrade     314 Package(s)
Total download size: 557 M
Is this ok [y/N]:y
(インストールとアップデートがされる)
・・・

使いはじめるとyum update(全パッケージアップデート)をしないから、初期セットアップ時ぐらいyum updateをする。

途中、以下のような警告がでたが、とりあえずyで問題ない。

・・・
(332/332): yum-3.2.29-43.el6.centos.noarch.rpm           | 996 kB     00:00
--------------------------------------------------------------------------------
Total                                           4.4 MB/s | 557 MB     02:07
警告: rpmts_HdrFromFdno: ヘッダ V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
Importing GPG key 0xC105B9DE:
 Userid : CentOS-6 Key (CentOS 6 Official Signing Key) <centos-6-key@centos.org>
 Package: centos-release-6-4.el6.centos.10.x86_64 (@anaconda-CentOS-201303020151.x86_64/6.4)
 From   : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
Is this ok [y/N]:y
・・・

終わった。

・・・
  yelp.x86_64 0:2.28.1-17.el6_3
  yum.noarch 0:3.2.29-43.el6.centos

Replaced:
  firefox.x86_64 0:10.0.12-1.el6.centos
  libreoffice-presenter-screen.x86_64 1:3.4.5.2-16.1.el6_3

Complete!
[root@xx.xx.xx.xx ~]#

OSのバージョンを確認したら、バージョン(6.4->6.5)が上がってた(´Д`)まあ、問題ない(だろう)。

[root@xx.xx.xx.xx ~]# cat /etc/redhat-release
CentOS release 6.5 (Final)

LDAPクライアント設定

既にLDAPサーバがあったので、それを参照するようにする。

LDAP関連のパッケージをインストール状況を確認する

[root@xx.xx.xx.xx ~]# yum list installed | grep ldap
apr-util-ldap.x86_64    1.3.9-3.el6_0.1 @anaconda-CentOS-201303020151.x86_64/6.4
openldap.x86_64         2.4.23-32.el6_4.1
python-ldap.x86_64      2.3.10-1.el6    @anaconda-CentOS-201303020151.x86_64/6.4

↓入っていないね(´・ω・`)

必要なパッケージをインストールする

[root@xx.xx.xx.xx ~]# yum install openldap-clients nss-pam-ldapd
・・・
Dependencies Resolved

================================================================================
 Package                Arch         Version                   Repository  Size
================================================================================
Installing:
 nss-pam-ldapd          x86_64       0.7.5-18.2.el6_4          base       152 k
 openldap-clients       x86_64       2.4.23-32.el6_4.1         base       165 k
Installing for dependencies:
 nscd                   x86_64       2.12-1.132.el6            base       219 k
 pam_ldap               x86_64       185-11.el6                base        88 k

Transaction Summary
================================================================================
Install       4 Package(s)

Total download size: 624 k
Installed size: 1.4 M
Is this ok [y/N]:y
・・・
Installed:
  nss-pam-ldapd.x86_64 0:0.7.5-18.2.el6_4
  openldap-clients.x86_64 0:2.4.23-32.el6_4.1

Dependency Installed:
  nscd.x86_64 0:2.12-1.132.el6           pam_ldap.x86_64 0:185-11.el6

Complete!

はいった。

LDAPクライアントを設定する

最近のバージョン(6.x?)だと、コンソールUIで設定できるらしい。楽だ\(^o^)/。

[root@xx.xx.xx.xx ~]# authconfig-tui 

f:id:Namihira:20131223183433j:plain

とりあえず、こんな感じに設定して「次」を選択。

f:id:Namihira:20131223183457j:plain

※サーバー:LDAPサーバのIPアドレス
※ベースDN:LDAPサーバで設定したDN

[OK]を押したら、なんか起動した。。。なにこれ?とりあえず無視。

[root@xx.xx.xx.xx ~]# authconfig-tui
sssd を起動中:                                             [  OK  ]

とりあえず設定完了しました。

動作確認を行う

アカウント情報を引けるか確認する

[root@xx.xx.xx.xx ~]# id namihira
uid=1001(namihira) gid=1001(namihira) 所属グループ=1001(namihira),10(wheel)

引けてる\(^o^)/

指定したアカウントになれるか確認する

[root@xx.xx.xx.xx ~]# su namihira
su: /bin/zsh: そのようなファイルやディレクトリはありません

(´;ω;`)ブワッ

zshが入っていなかったので、インストールする。

[root@xx.xx.xx.xx ~]# yum list installed | grep zsh
[root@xx.xx.xx.xx ~]# (なにも出ない。。。)
[root@xx.xx.xx.xx ~]#  yum install zsh
・・・
Is this ok [y/N]:y
・・・
Installed:
  zsh.x86_64 0:4.3.10-7.el6

Complete!

再度確認する。

[root@xx.xx.xx.xx ~]# su namihira
[namihira@xx.xx.xx.xx].%

なれた\(^o^)/

SSHでログインできるか確認する

[root@xx.xx.xx.xx ~]# ssh namihira@localhost
The authenticity of host 'localhost (::1)' can't be established.
RSA key fingerprint is 52:ee:35:7b:bb:4c:ae:12:c0:43:f6:76:82:47:3f:c9.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'localhost' (RSA) to the list of known hosts.
namihira@localhost's password:
Permission denied, please try again.
namihira@localhost's password:
Permission denied, please try again.
namihira@localhost's password:
Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
[root@xx.xx.xx.xx ~]#

(´・ω・`)あれ?ログインできない。

設定を調整する

初めて使った「authconfig-tui」を怪しみ、昔ながらの「/etc/pam.d/system-auth」などの設定を再確認したら、「ldap」ではなく「sss」という単語がちらりほらりとある。
それらを修正します。(結局、手作業\(^o^)/)

/etc/pam.d/system-authを修正する

「sss」を「ldap」へ修正する。

[root@xx.xx.xx.xx ~]# vi /etc/pam.d/system-auth
#%PAM-1.0
# This file is auto-generated.
# User changes will be destroyed the next time authconfig is run.
auth        required      pam_env.so
auth        sufficient    pam_unix.so nullok try_first_pass
auth        requisite     pam_succeed_if.so uid >= 500 quiet
#auth        sufficient    pam_sss.so use_first_pass
auth        sufficient    pam_ldap.so use_first_pass
auth        required      pam_deny.so

account     required      pam_unix.so broken_shadow
account     sufficient    pam_localuser.so
account     sufficient    pam_succeed_if.so uid < 500 quiet
#account     [default=bad success=ok user_unknown=ignore] pam_sss.so
account     [default=bad success=ok user_unknown=ignore] pam_ldap.so
account     required      pam_permit.so

password    requisite     pam_cracklib.so try_first_pass retry=3 type=
password    sufficient    pam_unix.so sha512 shadow nullok try_first_pass use_authtok
#password    sufficient    pam_sss.so use_authtok
password    sufficient    pam_ldap.so use_authtok
password    required      pam_deny.so

session     optional      pam_keyinit.so revoke
session     required      pam_limits.so
session     [success=1 default=ignore] pam_succeed_if.so service in crond quiet use_uid
session     required      pam_unix.so
#session     optional      pam_sss.so
session     optional      pam_ldap.so

/etc/pam.d/password-authを修正する

「sss」を「ldap」へ修正する。

[root@xx.xx.xx.xx ~]# vi /etc/pam.d/password-auth
#%PAM-1.0
# This file is auto-generated.
# User changes will be destroyed the next time authconfig is run.
auth        required      pam_env.so
auth        sufficient    pam_unix.so nullok try_first_pass
auth        requisite     pam_succeed_if.so uid >= 500 quiet
#auth        sufficient    pam_sss.so use_first_pass
auth        sufficient    pam_ldap.so use_first_pass
auth        required      pam_deny.so

account     required      pam_unix.so broken_shadow
account     sufficient    pam_localuser.so
account     sufficient    pam_succeed_if.so uid < 500 quiet
#account     [default=bad success=ok user_unknown=ignore] pam_sss.so
account     [default=bad success=ok user_unknown=ignore] pam_ldap.so
account     required      pam_permit.so

password    requisite     pam_cracklib.so try_first_pass retry=3 type=
password    sufficient    pam_unix.so sha512 shadow nullok try_first_pass use_authtok
#password    sufficient    pam_sss.so use_authtok
password    sufficient    pam_ldap.so use_authtok
password    required      pam_deny.so

session     optional      pam_keyinit.so revoke
session     required      pam_limits.so
session     [success=1 default=ignore] pam_succeed_if.so service in crond quiet use_uid
session     required      pam_unix.so
#session     optional      pam_sss.so
session     optional      pam_ldap.so

/etc/nsswitch.confを修正する

「sss」を「ldap」へ修正する。

[root@xx.xx.xx.xx ~]# vi /etc/nsswitch.conf
・・・
#passwd:     files sss
#shadow:     files sss
#group:      files sss

passwd:     files ldap
shadow:     files ldap
group:      files ldap
・・・
rpc:        files
#services:   files sss
services:   files ldap

#netgroup:   files sss
netgroup:   files ldap
・・・

nslcdの再起動と自動起動設定をする

[root@xx.xx.xx.xx ~]# /etc/init.d/nslcd restart
nslcd を停止中:                                            [失敗]
nslcd を起動中:                                            [  OK  ]
[root@xx.xx.xx.xx ~]# chkconfig --list | grep nslcd
nslcd           0:off   1:off   2:off   3:off   4:off   5:off   6:off
[root@xx.xx.xx.xx ~]# chkconfig nslcd on
[root@xx.xx.xx.xx ~]# chkconfig --list | grep nslcd
nslcd           0:off   1:off   2:on    3:on    4:on    5:on    6:off

動作確認を行う

SSHでログインできるか確認する(ローカルからのログイン)

[root@xx.xx.xx.xx ~]# ssh namihira@localhost
namihira@localhost's password:
Could not chdir to home directory /home/namihira: No such file or directory
[namihira@xx.xx.xx.xx]/%
[namihira@xx.xx.xx.xx]/% pwd
/

とりあえずログインできた\(^o^;)/エラーでたけど。

SSHでログインできるか確認する(リモートからのログイン)

login as: namihira
namihira@xx.xx.xx.xx 's password:
Last login: Mon Dec 23 16:39:53 2013 from localhost
Could not chdir to home directory /home/namihira: No such file or directory
[namihira@xx.xx.xx.xx]/% pwd
/

とりあえずログインできた\(^o^;)/エラーでたけど。

再起動してもSSHでログインできるか確認する(リモートからのログイン)

[root@xx.xx.xx.xx ~]# reboot
Broadcast message from root@xx.xx.xx.xx
        (/dev/pts/0) at 16:46 ...

The system is going down for reboot NOW!
[root@xx.xx.xx.xx ~]# 


login as: namihira
namihira@xx.xx.xx.xx 's password:
Last login: Mon Dec 23 16:42:55 2013 from 10.61.62.22
Could not chdir to home directory /home/namihira: No such file or directory
[namihira@xx.xx.xx.xx]/% pwd
/

とりあえずログインできた\(^o^;)/エラーでたけど。

LDAPクライアントの設定完了しました。

ログインしたらホームディレクトリを作成するようにする

上記でログインしたら、ホームディレクトリがなくメッセージがでるので、ログインしたらホームディレクトリを作成するように設定を行います。

/etc/pam.d/system-authを修正する

下記の記載を追加する

[root@xx.xx.xx.xx ~]# vi /etc/pam.d/system-auth
・・・
session     optional      pam_oddjob_mkhomedir.so skel=/etc/skel umask=022
[root@xx.xx.xx.xx ~]# vi /etc/pam.d/password-auth
・・・
session     optional      pam_oddjob_mkhomedir.so skel=/etc/skel umask=022
[root@xx.xx.xx.xx ~]# /etc/init.d/oddjobd start
oddjobd を起動中:                                          [  OK  ]
[root@xx.xx.xx.xx ~]# chkconfig oddjobd on

/etc/pam.d/password-authを修正する

下記の記載を追加する

[root@xx.xx.xx.xx ~]# vi /etc/pam.d/password-auth
・・・
session     optional      pam_oddjob_mkhomedir.so skel=/etc/skel umask=022

oddjobdを起動と再起動設定を行う

下記の記載を追加する

[root@xx.xx.xx.xx ~]# /etc/init.d/oddjobd start
oddjobd を起動中:                                          [  OK  ]
[root@xx.xx.xx.xx ~]# chkconfig oddjobd on

補足

最初「pam_mkhomedir.so」を指定しディレクトリ自動生成を実現しようとしましたが、なぜかログインしてもディレクトリが自動生成されず、「pam_oddjob_mkhomedir.soを指定」+「oddjobd起動」で自動生成されるようになりました。CentOS 6.xの仕様?

動作確認を行う

ログインしてみる。

login as: namihira
namihira@xx.xx.xx.xx's password:
Creating home directory for namihira.
Last login: Mon Dec 23 17:49:06 2013 from localhost
[namihira@xx.xx.xx.xx]~% pwd
/home/namihira
[namihira@xx.xx.xx.xx]~%

ディレクトリ作成された\(^o^)/

まとめ

CentOS 5.xとCentOS 6.xではLDAP設定が結構異なり苦労しました。本来ならば「authconfig-tui」で一発設定できると思いますが、「pam_sss」あたりが理解できていないので、結局今回設定をごりごり手動で設定しました。
メジャーバージョンが異なるサーバの設定は、要注意です。

後日談

sudoについての調整が必要で、実施しました。
CentOS6.5のLDAPクライアントのsudo設定 - なみひらブログ