NIS(Network Information Service,or Yellow Page or YP) 網絡信息服務,由sun公司開發並受權給unix供應商,最初稱爲黃頁,簡稱YP,因爲 British Telecom PLC公司優先註冊了Yellow Page商標,因此sun公司最終將其更名爲NIS,可是其應用程序或腳本仍延用以yp開頭。
NIS是一種應用層協議,以客戶端/服務器端的方式工做,主要做用是在網絡中提供輕型目錄服務,如存儲用戶或組賬號信息,計算機名信息等。就像windows中的AD,集中存儲用戶的賬號信息,計算機信息,這樣方便管理賬號,在中大型企業中應用普遍。固然NIS不只能夠進行賬號的統一管理,還能夠結合kerberos作應用服務的驗證,如:ftp ssh等。node
NIS服務是C/S模式,NIS服務器能夠多臺,分爲master/slave模式,主服務器負責數據庫製做管理,從服務器負責從主服務器更新數據而且提供與master 相同的查尋功能!
NIS的服務器集中維護用戶的帳號信息,當NIS客戶機須要進行用戶登陸的信息驗證時,就向NIS服務器發出查詢請求。當系統中的一臺NIS服務器爲多臺NIS客戶機提供服務時,用戶登陸系統中的任何一臺NIS客戶機都會從NIS服務器進行登陸驗證,這樣就實現了集中管理用戶帳號的功能。
在NIS服務器的數據庫中主要包含如下幾類信息:用戶帳號信息,組帳號信息,IP地址和主機名稱對應記錄的信息,這些信息被保存在不一樣的數據庫文件中進行集中的管理。web
NIS客戶端配置文件數據庫
kerberos希臘語是看門狗的意思,由MIT研發,目前最新版應該第5版。kerberos驗證過程有點複雜,曾經MIT在1988年寫了一篇有趣的文章,使用對話的方式將整個過程描述出來,它就是雅典娜和歐里庇得斯的對話,有興趣的朋友能夠去閱讀一下,能夠很好的幫助理解kerberos。windows
條目 | 寫法 |
---|---|
user : | user/描述@xxx.com |
ftp server: | ftp/hostname@xxx.com |
ssh server: | host/hostname@xxx.com |
telnet ser: | host/hostname@xxx.com |
nfs server: | nfs/hostname@xxx.com |
kerberos驗證過程分爲2步,初始驗證過程和票據驗證過程安全
以client請求登陸ssh服務爲例:bash
IP | 主機名 | 功能 |
---|---|---|
192.168.5.10 | master.example.com | NIS主服務器master+kerberos服務 |
192.168.5.11 | node1.example.com | NIS從服務器slave |
192.168.5.12 | node2.example.com | ssh server+kerberos workstation |
192.168.5.13 | node3.example.com | nis client+kerberos workstation |
[root@master ~]# yum install -y ypserv yp-tools [root@node1 ~]# yum install -y ypserv yp-tools
[root@node3 ~]# yum install -y yp-tools
[root@master ~]# systemctl start rpcbind [root@master ~]# systemctl enable rpcbind [root@node1 ~]# systemctl start rpcbind [root@node1 ~]# systemctl enable rpcbind
[root@master ~]# rpcinfo -p localhost program vers proto port service 100000 4 tcp 111 portmapper 100000 3 tcp 111 portmapper 100000 2 tcp 111 portmapper 100000 4 udp 111 portmapper 100000 3 udp 111 portmapper 100000 2 udp 111 portmapper
[root@master ~]# cat /etc/hosts 192.168.5.10 master master.example.com 192.168.5.11 node1 node1.example.com 192.168.5.12 node2 node2.example.com 192.168.5.13 node3 node3.example.com
[root@master yp]# cat /var/yp/ypservers master node1
NOPUSH=false #容許主服務器向從服務器傳遞數據庫文件
[root@master yp]# systemctl restart ypserv [root@master yp]# systemctl restart ypbind [root@master yp]# systemctl restart yppasswdd [root@master yp]# systemctl restart ypxfrd
[root@master ~]# /usr/lib64/yp/ypinit -m At this point, we have to construct a list of the hosts which will run NIS servers. master is in the list of NIS server hosts. Please continue to add the names for the other hosts, one per line. When you are done with the list, type a <control D>. next host to add: master next host to add: 按ctrl+d保存 The current list of NIS servers looks like this: master Is this correct? [y/n: y] y We need a few minutes to build the databases... Building /var/yp/master.example.com/ypservers... Running /var/yp/Makefile... gmake[1]: Entering directory `/var/yp/master.example.com' Updating passwd.byname... Updating passwd.byuid... Updating group.byname... Updating group.bygid... Updating hosts.byname... Updating hosts.byaddr... Updating rpc.byname... Updating rpc.bynumber... Updating services.byname... Updating services.byservicename... Updating netid.byname... Updating protocols.bynumber... Updating protocols.byname... Updating mail.aliases... gmake[1]: Leaving directory `/var/yp/master.example.com' master has been set up as a NIS master server. Now you can run ypinit -s master on all slave server.
最終在/var/yp目錄下生成數據庫文件,查看一下服務器
[root@master ~]# ls /var/yp/ Makefile master.example.com ypservers [root@master ~]# ls /var/yp/master.example.com/ group.bygid mail.aliases protocols.byname services.byname group.byname netid.byname protocols.bynumber services.byservicename hosts.byaddr passwd.byname rpc.byname ypservers hosts.byname passwd.byuid rpc.bynumber
[root@master ~]# useradd sshu [root@master ~]# passwd sshu Changing password for user sshu. New password: BAD PASSWORD: The password is shorter than 8 characters Retype new password: passwd: all authentication tokens updated successfully.
[root@master ~]# make -C /var/yp/ make: Entering directory `/var/yp' gmake[1]: Entering directory `/var/yp/master.example.com' Updating passwd.byname... Updating passwd.byuid... Updating group.byname... Updating group.bygid... Updating netid.byname... gmake[1]: Leaving directory `/var/yp/master.example.com' make: Leaving directory `/var/yp'
使用NIS客戶端工具查看數據庫信息已經有了剛添加的sshu用戶信息網絡
[root@master ~]# ypcat -d master.example.com -h master.example.com passwd sshu:$6$WrW8Lw06$/.WxYeOBxJ02aV0u3SVzeZ2sz/2csruFdmUcjYbEiA/vLhorYVC2XCUOpGEKpuG1ImGFq87BL61sy4puUWNLO1:1000:1000::/home/frank:/bin/bash
[root@node1 ~]# /usr/lib64/yp/ypinit -s master We will need a few minutes to copy the data from master. Transferring netid.byname... Trying ypxfrd ... success Transferring group.bygid... Trying ypxfrd ... success Transferring group.byname... Trying ypxfrd ... success Transferring passwd.byuid... Trying ypxfrd ... success Transferring passwd.byname... Trying ypxfrd ... success Transferring mail.aliases... Trying ypxfrd ... success Transferring protocols.byname... Trying ypxfrd ... success Transferring protocols.bynumber... Trying ypxfrd ... success Transferring services.byservicename... Trying ypxfrd ... success Transferring services.byname... Trying ypxfrd ... success Transferring rpc.bynumber... Trying ypxfrd ... success Transferring rpc.byname... Trying ypxfrd ... success Transferring hosts.byaddr... Trying ypxfrd ... success Transferring hosts.byname... Trying ypxfrd ... success Transferring ypservers... Trying ypxfrd ... success node1's NIS data base has been set up. If there were warnings, please figure out what went wrong, and fix it. At this point, make sure that /etc/passwd and /etc/group have been edited so that when the NIS is activated, the data bases you have just created will be used, instead of the /etc ASCII files.
[root@node1 ~]# ypcat -h node1.example.com passwd frank:$6$WrW8Lw06$/.WxYeOBxJ02aV0u3SVzeZ2sz/2csruFdmUcjYbEiA/vLhorYVC2XCUOpGEKpuG1ImGFq87BL61sy4puUWNLO1:1000:1000::/home/frank:/bin/bash sshu:$6$K6XRNhSk$st/0cfN6GAq8maTFlPQktxqQwKFPLeOQ97JpqkApQ9EwzwKqsNzIo5OEYeyv9LFMD6bU25367BYeuv4NsjSOy1:1001:1001::/home/u123:/bin/bash
代表數據同步成功,固然不可能每次都要手動同步,設置個定時任務計劃即可以解決這個問題。架構
在master服務器上添加任務計劃併發
5 * * * * /usr/sbin/yppush -h node1.example.com passwd.byname 5 * * * * /usr/sbin/yppush -h node1.example.com passwd.byuid 5 * * * * /usr/sbin/yppush -h node1.example.com group.byname 5 * * * * /usr/sbin/yppush -h node1.example.com group.bygid
[root@node3 ~]# authconfig-tui
經過終端登陸測試 OK 驗證成功
能夠以/var/yp/目錄下建立securenets文件來限制網絡主機查看NIS服務器的數據庫
[root@master yp]# vi securenets [root@master yp]# cat !$ cat securenets 255.255.255.255 192.168.5.11
表示容許5.11的主機能夠查看NIS數據庫
[root@node1 ~]# ypcat -d master.example.com -h master.example.com passwd frank:$6$WrW8Lw06$/.WxYeOBxJ02aV0u3SVzeZ2sz/2csruFdmUcjYbEiA/vLhorYVC2XCUOpGEKpuG1ImGFq87BL61sy4puUWNLO1:1000:1000::/home/frank:/bin/bash [root@node1 ~]# ifconfig | grep inet |grep 192 inet 192.168.5.11 netmask 255.255.255.0 broadcast 192.168.5.255
[root@node2 ~]# ifconfig |grep inet |grep 5.12 inet 192.168.5.12 netmask 255.255.255.0 broadcast 192.168.5.255 [root@node2 ~]# ypcat -d master.example.com -h master.example.com passwd No such map passwd.byname. Reason: No such map in server's domain
在master上安裝 krb5-server krb5-workstation,在node2和node3安裝krb5-workstation
[root@master ~]# yum -y install krb5-server krb5-workstation [root@node2 ~]# yum -y install krb5-workstation [root@node3 ~]# yum -y install krb5-workstation
[realms] //表示域 # EXAMPLE.COM = { # kdc = kerberos.example.com # admin_server = kerberos.example.com # } MASTER.EXAMPLE.COM = { //域名稱隨便寫,通常大寫,能夠和NIS域名不一樣 kdc = 192.168.5.10 //kdc主機地址 admin_server = 192.168.5.10 //管理主機地址 } [domain_realm] .example.com = MASTER.EXAMPLE.COM //表示後輟爲example.com全部域成員
這個配置文件凡是裝有krb5-workstation的主機都要有一份
[root@master ~]# for i in {2,3};do scp /etc/krb5.conf node$i:/etc/krb5.conf;done root@node2's password: krb5.conf 100% 835 121.9KB/s 00:00 root@node3's password: krb5.conf 100% 835 280.8KB/s 00:00
[root@master ~]# vi /var/kerberos/krb5kdc/kdc.conf [kdcdefaults] kdc_ports = 88 kdc_tcp_ports = 88 [realms] EXAMPLE.COM = { master_key_type = aes256-cts //取消本行的註釋 default_principal_flags = +preauth //增長本行,表示預驗證 acl_file = /var/kerberos/krb5kdc/kadm5.acl dict_file = /usr/share/dict/words admin_keytab = /var/kerberos/krb5kdc/kadm5.keytab supported_enctypes = aes256-cts:normal aes128-cts:normal des3-hmac-sha1:normal arcfour-hmac:normal camellia256-cts:normal camellia128-cts:normal des-hmac-sha1:normal des-cbc-md5:normal des-cbc-crc:normal }
[root@master ~]# vi /var/kerberos/krb5kdc/kadm5.acl */admin@MASTER.EXAMPLE.COM * 第一*表示用戶,第二*表示權限 權限可選擇的配置列表以下: a: 容許增長principal或訪問策略 A: 不容許增長principal或訪問策略 c: 容許變動principals的密碼 C: 不容許變動princials的密碼 d: 容許刪除principals或策略 D: 不容許刪除principals或策略 i: 容許查看數據庫 I: 不容許查看數據庫 l: 容許列出principals或策略列表 L: 不容許列出principals或策略 m: 容許修改principals或策略 M: 不容許修改principals或策略 p: 容許傳播(propagation)principal數據庫 P: 不容許傳播principal數據庫 u: 容許建立使用PAM進行密碼驗證的單一組件用戶principal U: 否決u的權限 x: a,d,m,c,i,l權限的快捷方式 *: 跟x同樣
這裏的admin賬號系統中尚未,須要後面建立
[root@master ~]# kdb5_util create -r MASTER.EXAMPLE.COM -s Loading random data Initializing database '/var/kerberos/krb5kdc/principal' for realm 'MASTER.EXAMPLE.COM', master key name 'K/M@MASTER.EXAMPLE.COM' You will be prompted for the database Master Password. It is important that you NOT FORGET this password. Enter KDC database master key: //提示輸入KDC數據庫密碼,不能忘記 Re-enter KDC database master key to verify:
[root@master ~]# systemctl start krb5kdc && systemctl enable krb5kdc Job for krb5kdc.service failed because the control process exited with error code. See "systemctl status krb5kdc.service" and "journalctl -xe" for details.
出了錯,先看看日誌
[root@master ~]# tail /var/log/krb5kdc.log krb5kdc: Configuration file does not specify default realm - while attempting to retrieve default realm krb5kdc: Configuration file does not specify default realm - while attempting to retrieve default realm krb5kdc: Configuration file does not specify default realm - while attempting to retrieve default realm
日誌說配置文件裏沒有默認的域 在/etc/krb5.conf配置文件裏檢查下,果真是有一行默認域被註釋
[root@master ~]# !vi vi /etc/krb5.conf # Configuration snippets may be placed in this directory as well includedir /etc/krb5.conf.d/ [logging] default = FILE:/var/log/krb5libs.log kdc = FILE:/var/log/krb5kdc.log admin_server = FILE:/var/log/kadmind.log [libdefaults] dns_lookup_realm = false ticket_lifetime = 24h renew_lifetime = 7d forwardable = true rdns = false # default_realm = EXAMPLE.COM default_realm = MASTER.EXAMPLE.COM //問題就出在這裏
再次啓動服務,OK問題解決
[root@master ~]# systemctl start kadmin [root@master ~]# systemctl enable kadmin Created symlink from /etc/systemd/system/multi-user.target.wants/kadmin.service to /usr/lib/systemd/system/kadmin.service. [root@master ~]# systemctl start krb5kdc [root@master ~]# systemctl enable krb5kdc Created symlink from /etc/systemd/system/multi-user.target.wants/krb5kdc.service to /usr/lib/systemd/system/krb5kdc.service.
[root@master ~]# kadmin.local Authenticating as principal root/admin@MASTER.EXAMPLE.COM with password. kadmin.local: listprincs //查看當前系統中的principal K/M@MASTER.EXAMPLE.COM kadmin/admin@MASTER.EXAMPLE.COM kadmin/changepw@MASTER.EXAMPLE.COM kadmin/master@MASTER.EXAMPLE.COM kiprop/master@MASTER.EXAMPLE.COM krbtgt/MASTER.EXAMPLE.COM@MASTER.EXAMPLE.COM kadmin.local: addprinc root/admin@MASTER.EXAMPLE.COM //添加一個principal WARNING: no policy specified for root/admin@MASTER.EXAMPLE.COM; defaulting to no policy Enter password for principal "root/admin@MASTER.EXAMPLE.COM": Re-enter password for principal "root/admin@MASTER.EXAMPLE.COM": Principal "root/admin@MASTER.EXAMPLE.COM" created. kadmin.local: listprincs K/M@MASTER.EXAMPLE.COM kadmin/admin@MASTER.EXAMPLE.COM kadmin/changepw@MASTER.EXAMPLE.COM kadmin/master@MASTER.EXAMPLE.COM kiprop/master@MASTER.EXAMPLE.COM krbtgt/MASTER.EXAMPLE.COM@MASTER.EXAMPLE.COM root/admin@MASTER.EXAMPLE.COM kadmin.local:
kadmin.local: addprinc u123@MASTER.EXAMPLE.COM //注意用戶pirncipal的寫法 WARNING: no policy specified for u123@MASTER.EXAMPLE.COM; defaulting to no policy Enter password for principal "sshu@MASTER.EXAMPLE.COM": Re-enter password for principal "sshu@MASTER.EXAMPLE.COM": Principal "sshu@MASTER.EXAMPLE.COM" created. kadmin.local: addprinc -randkey host/master.example.com@MASTER.EXAMPLE.COM //注意SSH主機pirncipal的寫法 WARNING: no policy specified for host/master.example.com@MASTER.EXAMPLE.COM; defaulting to no policy Principal "host/master.example.com@MASTER.EXAMPLE.COM" created. kadmin.local: ktadd host/master.example.com@MASTER.EXAMPLE.COM Entry for principal host/master.example.com@MASTER.EXAMPLE.COM with kvno 2, encryption type aes256-cts-hmac-sha1-96 added to keytab WRFILE:/etc/krb5.keytab. Entry for principal host/master.example.com@MASTER.EXAMPLE.COM with kvno 2, encryption type aes128-cts-hmac-sha1-96 added to keytab WRFILE:/etc/krb5.keytab. kadmin.local: ktadd sshu@MASTER.EXAMPLE.COM [root@master ~]# restorecon /etc/krb5.keytab //可選操做
GSSAPIAuthentication yes
這裏提示有個包沒有安裝,安裝一下
[root@node3 ~]# yum -y install pam_krb5
配置完成
[root@node3 ~]# kdestroy Other credential caches present, use -A to destroy all [root@node3 ~]# kinit sshu Password for sshu@MASTER.EXAMPLE.COM: [root@node3 ~]# klist Ticket cache: KEYRING:persistent:0:0 Default principal: sshu@MASTER.EXAMPLE.COM Valid starting Expires Service principal 11/28/2018 18:40:12 11/29/2018 18:40:09 krbtgt/MASTER.EXAMPLE.COM@MASTER.EXAMPLE.COM [root@node3 ~]# ssh sshu@master.example.com Last login: Tue Nov 27 20:40:30 2018 from 192.168.5.13 [sshu@master ~]$ exit logout Connection to master.example.com closed. [root@node3 ~]# ssh sshu@node2.example.com Last login: Tue Nov 27 20:40:20 2018 from 192.168.5.13 Could not chdir to home directory /home/sshu: No such file or directory -bash-4.2$
完成ssh免密碼登陸。
nis服務器上只存賬號信息,驗證功能交給kerberos完成,這裏須要注意的是,nis中的賬號在kerberos中也要有,若是kerberos有賬號而nis中沒有不能完成驗證。 Nis中的賬戶須要同步到kerberos中,而用戶的密碼能夠不一樣。 kerberos驗證安全可靠,也被衆多廠商支持,咱們熟知的微軟公司就將kerberos揉合進了AD,無需作任何操做就幫咱們作好了驗證功能。