RHEL7-openldap安裝配置二(客戶端安裝配置)


LDAP用戶登錄流程:

當在客戶端輸入賬號登錄系統時,系統根據/etc/nsswitch.conf配置文件獲取賬號查找順序,然后再根據PAM配置文件調用相關模塊,對賬號(/etc/passwd)及密碼(/etc/shadow)進行查找並進行匹配。當本地匹配不成功時,會通過后端認證服務器(OpenLDAP服務器)進行驗證。

主要的幾個配置文件說明:

  • /etc/nsswitch.conf 該文件主要用於名稱轉換服務,用於系統驗證用戶身份所讀取本地文件或是遠程驗證服務器文件。

  • /etc/sysconfig/authconfig 主要用於提供身份驗證之LDAP功能,該配置文件用來跟蹤LDAP身份認證機制是否正確啟用。

  • /etc/pam.d/system-auth 主要用於實現用戶賬戶身份驗證。

  • /etc/pam_ldap.conf 實現客戶端與服務端的交互。(rhel7沒有該配置文件)

  • /etc/openldap/ldap.conf 主要用於查詢OpenLDAP服務器所有條目信息。

安裝客戶端軟件包

yum install -y openldap-clients nss-pam-ldapd

配置Openldapclient

將LDAP服務器端主機名和IP地址的解析記錄寫入到/etc/hosts文件,因為我們沒有配置DNS方式來解析主機或,所以就簡單地寫入到hosts文件里。

#echo "192.168.100.200 server0.ultrapower.com" >> /etc/hosts

3種配置圖LDAP客戶端的方式
1、圖形界面配置方式
[root@desktop0 ~]# authconfig-gtk ---默認沒有安裝該工具,yum install authcongif-gtk 安裝之后才能使用。

或者[root@desktop0 ~]# system-config-authentication

L

LDAP server:填寫主機名或IP都可以。開頭的’ldap://‘可以省略不寫。

密鑰獲取通過http方式,因為我們在服務器端已經安裝配置了httpd服務,並且已經把公鑰文件cert.pem放到網站默認目錄下了。

另外兩種配置方式則使用scp方式拷貝密鑰文件。

2、字符界面配置方式

[root@desktop0 ~]#authconfig-tui 

或者直接輸入setup命令,選擇Authentication configuration。之后的界面界面同上。

對比修改前后的配置文件:

1、/etc/nsswitch.conf 配置文件

 

2、/etc/pam.d/system-auth-ac配置文件

3、/etc/nslcd.conf 

uri ldap://server0.ultrapower.com/
base dc=ultrapower,dc=com
ssl start_tls
tls_cacertdir /etc/openldap/cacerts

3、命令行配置方式

As the authconfig-tui is deprecated, to configure the LDAP client side, there are two available options: nslcd and sssd.
In this tutorial, the nslcd option will be used, see the authconfig tutorial for the sssd option.

nslcd方式

# authconfig --enableforcelegacy --update
# authconfig --enableldap --enableldapauth --ldapserver="server0.ultrapower.com" --ldapbasedn="dc=ultrapower,dc=com" --update
# scp 方式獲取密鑰
# authconfig --enableldaptls --update

也可以加上這個參數–enablemkhomedir ,ldap用戶在登錄系統時自動創建家目錄。但是我們要使用nfs服務器上的共享目錄,所以這里不需要該參數。

Note1: According to your requirements, you can need to specify the –enablemkhomedir option after the installation of the oddjob-mkhomedir package. The option creates a local user home directory at the first connection if none exists.
Note2: Type # authconfig –help | grep ldap to remember the necessary options.

[root@desktop2 ~]# authconfig --help | grep ldap
    --enableldap            enable LDAP for user information by default
    --disableldap           disable LDAP for user information by default
    --enableldapauth        enable LDAP for authentication by default
    --disableldapauth       disable LDAP for authentication by default
  --ldapserver=<server>
    --ldapbasedn=<dn>       default LDAP base DN --enableldaptls, --enableldapstarttls --disableldaptls, --disableldapstarttls --ldaploadcacert=<URL> [root@desktop2 ~]# 

ssd方式:

# yum install -y sssd
# authconfig --enableldap --enableldapauth --ldapserver="server0.ultrapower.com" --ldapbasedn="dc=ultrapower,dc=com" --update # scp root@192.168.100.200:/etc/openldap/certs/cert.pem /etc/openldap/cacerts/ # authconfig --enableldaptls --update

最后,我們要獲取服務器端公鑰文件並測試

把服務器端的密鑰文件放到客戶機/etc/openldap/cacerts目錄下

[root@desktop1 ~]# scp root@192.168.100.200:/etc/openldap/certs/cert.pem /etc/openldap/cacerts/

測試:

[root@desktop1 ~]# ping server0.ultrapower.com  --必須能夠ping通服務器主機名
PING server0.ultrapower.com (192.168.100.200) 56(84) bytes of data. 64 bytes from server0.ultrapower.com (192.168.100.200): icmp_seq=1 ttl=64 time=0.417 ms ^C --- server0.ultrapower.com ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 0.417/0.417/0.417/0.000 ms [root@desktop1 ~]# id testldapuser1 uid=1001(testldapuser1) gid=1001(testldapuser1) groups=1001(testldapuser1) [root@desktop1 ~]# id testldapuser3 uid=1003(testldapuser3) gid=1003(testldapuser3) groups=1003(testldapuser3) [root@desktop1 ~]# 

切換到ldap用戶時提示沒有用戶目錄:

[root@desktop1 ~]# su - testldapuser1
su: warning: cannot change directory to /home/guests/testldapuser1: No such file or directory
-bash-4.2$

如果我們勾選下圖選項,則切換到LDAP用戶時,會自動創建用戶的家目錄:

[root@desktop1 ~]# id testldapuser8
uid=1008(testldapuser8) gid=1008(testldapuser8) groups=1008(testldapuser8) [root@desktop1 ~]# ls /home/ rusky [root@desktop1 ~]# su - testldapuser8 Creating home directory for testldapuser8. [testldapuser8@desktop1 ~]$ pwd /home/guests/testldapuser8

 [testldapuser8@desktop1 ~]$ touch testfile8
  [testldapuser8@desktop1 ~]$ ls
  testfile8

但是會出現一個這樣的問題,如果用戶在不同的客戶機上都創建自己的家目錄,無法做到在不同的客戶機下共享家目錄。比如上面的testldpauser8用戶在desktop1上登錄時,創建了一個testfile8文件,下一次從desktop2上登錄時是看不到這個文件的,因為該文件是保存在客戶機本地。所以下一篇文章中,我們將使用NFS服務為每個用戶都創建自己自己的共享目錄,用戶從不同的客戶機上登錄時,都掛載使用NFS服務器上的共享目錄,這樣就能保證用戶家目錄下的文件一致了。

參考文檔:

https://www.certdepot.net/ldap-client-configuration-authconfig/

http://www.linuxidc.com/Linux/2016-08/134228.htm


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM