Kerberos+LDAP+NFSv4 實現單點登陸(中)

Kerberos+LDAP+NFSv4 實現單點登陸(中)linux

五.nfs服務器的安裝
1.安裝nfs-kernel-server
root@debian:~# apt-get install nfs-kernel-server nfs-commonapi

修改/etc/default/nfs-kernel-server文件

NEED_SVCGSSD=""
改成
NEED_SVCGSSD="yes"安全

重啓nfs-kernel-server服務器

root@debian:~# /etc/init.d/nfs-kernel-server stop
root@debian:~# /etc/init.d/nfs-kernel-server start
root@debian:~# ps -e |grep gss
10275 ?        00:00:00 rpc.svcgssd

2.安裝libnss-ldapd、nslcd
爲了獲取ldap用戶信息,要安裝libnss-ldapd、nslcd
在新立得選上libnss-ldapd、nslcd會自動將libpam-ldapd、nscd、nslcd-utils三個包打上安裝標記,可手工將該三個包去掉安裝標記,不需此三個包網絡

root@debian:~# apt-get install libnss-ldapd nslcddom

注意安裝nslcd配置過程當中,提示輸入LDAP服務器地址的輸入框默認了uri ldapi:/// ,必定要將 ldapi 改成 ldap ,由於ldapi:///表示用在unix域ide

1)nslcd
安裝過程當中
ldap server uri 填 ldap://192.168.1.101/
ldap服務器搜索起點 填 dc=ctp,dc=net測試

查看配置文件ui

root@debian:~# cat /etc/nslcd.conf
#The user and group nslcd should run as.
uid nslcd
gid nslcd

#The location at which the LDAP server(s) should be reachable.
#填LDAP服務器地址,即kdc服務器地址
uri ldap://192.168.1.101/

#The search base that will be used for all queries.
base dc=ctp,dc=net

root@debian:~#

2)libnss-ldapd
安裝過程當中
name services to configure 選 [*] passwdthis

新建測試目錄
root@debian:~# mkdir /home/linlin/share

將該目錄屬性改成用戶ID及用戶組ID都爲4001,即爲ldap用戶krblinlin的uidNumber/gidNumber,但並在nfs客/服兩主機本地不存在該ID用戶
root@debian:~# chown 4001:4001 /home/linlin/share

2.1)假定沒選[*] passwd

linlin@debian:~$ ls -ld /home/linlin/share
drwxr-xr-x 2 4001 4001 4096 9月  18 21:13 /home/linlin/share

則取不到ldap用戶信息

2.2)可重設libnss-ldapd,選上[*] passwd
root@debian:~# dpkg-reconfigure libnss-ldapd

...
┌───────────┤  正在設定 libnss-ldapd  ├──────────────────────────┐  
│  For this package to work, you need to modify the /etc/nsswitch.conf file to use the ldap datasource. │  
│  You can select the services that should have LDAP lookups enabled. The new LDAP lookups will be added│
│as the last datasource. Be sure to review these changes.                                               │  
│  Name services to configure:                                                                          │  
│    [ ] hosts                                                                                          │  
│    [ ] netgroup                                                                                       │  
│    [ ] networks                                                                                       │  
│    [*] passwd                                                                                         │  
│    [ ] protocols                                          
...

/etc/nsswitch.conf: enable LDAP lookups for passwd
root@debian:~#

查看配置文件,可見passwd一行後添加了ldap

root@debian:~# cat /etc/nsswitch.conf
passwd:         compat ldap
group:          compat
shadow:         compat
gshadow:        files

hosts:          files mdns4_minimal [NOTFOUND=return] dns
networks:       files

protocols:      db files
services:       db files
ethers:         db files
rpc:            db files

netgroup:       nis
root@debian:~#
linlin@debian:~$ ls -ld /home/linlin/share
drwxr-xr-x 2 krblinlin 4001 4096 9月  18 21:13 /home/linlin/share

則已獲取顯示ldap用戶信息,krblinlin爲ldap用戶,同時也是Kerberos用戶
獲取用戶信息很重要,由於nfs客/服兩端的認證用戶信息要匹配,即兩邊的域+用戶名要一致

注:本實驗只獲取ldap用戶的用戶名,沒法獲取ldap用戶的所屬用戶組名(如上仍顯示用戶組ID 4001),但不影響實驗效果

3.網絡共享
本實驗目的NFSv4認證採用安全性強的gss/krb5認證(Kerberos),而不是弱的系統認證(AUTH_SYS)

編輯/etc/exports文件

root@debian:~# cat /etc/exports
/home/linlin/share  gss/krb5(rw,sync,no_subtree_check)
root@debian:~#

執行導出
root@debian:~# exportfs -r

查看導出

root@debian:~# exportfs -v
/home/linlin/share
        gss/krb5(rw,wdelay,root_squash,no_subtree_check,sec=sys,rw,root_squash,no_all_squash)
root@debian:~#

4.問題解決
nfs服務器沒有啓動rpc.idmapd,致使nfs客戶機沒寫權限
1)

root@debian:~# rpc.idmapd
rpc.idmapd: libnfsidmap: using (default) domain: ctp.net
rpc.idmapd: libnfsidmap: Realms list: 'CTP.NET'
rpc.idmapd: libnfsidmap: loaded plugin /lib/x86_64-linux-gnu/libnfsidmap/nsswitch.so for method nsswitch

root@debian:~# ps -e|grep rpc
  634 ?        00:00:00 rpciod
  757 ?        00:00:00 rpcbind
 1188 ?        00:00:00 rpc.svcgssd
 1261 ?        00:00:00 rpc.mountd
root@debian:~#

手工運行rpc.idmapd仍沒啓動rpc.idmapd

2)
原來nfs服務器的nfs-common要重啓

root@debian:~# /etc/init.d/nfs-common stop
root@debian:~# /etc/init.d/nfs-common start

root@debian:~# ps -e|grep rpc
  634 ?        00:00:00 rpciod
  757 ?        00:00:00 rpcbind
14256 ?        00:00:00 rpc.svcgssd
14258 ?        00:00:00 rpc.mountd
15023 ?        00:00:00 rpc.statd
15041 ?        00:00:00 rpc.idmapd
root@debian:~#

nfs客戶機已可寫權限了
相關文章
相關標籤/搜索