url:https://blog.51cto.com/lansgg/1544951




1.快速登录主机(无需输入密码)

cp /usr/share/doc/sudo-1.8.6p3/schema.OpenLDAP /etc/openldap/schema/sudo.schema

vim /etc/openldap/slapd.conf

18 include         /etc/openldap/schema/sudo.schema

rm -rf /etc/openldap/slapd.d/*

slaptest -f /etc/openldap/slapd.conf -F /etc/openldap/slapd.d/

chown -R ldap:ldap /etc/openldap/slapd.d/*

/etc/init.d/slapd restart


2.编辑sudo权限的ldif文件

[root@master ~]# vim sudo.ldif

 

dn: ou=sudoers,dc=lansgg,dc=com

objectClass: top

objectClass: organizationalUnit

ou: sudoers

 

dn: cn=defaults,ou=sudoers,dc=lansgg,dc=com

objectClass: top

objectClass: sudoRole

cn: defaults

sudoOption: !visiblepw

sudoOption: always_set_home

sudoOption: env_reset

sudoOption: requiretty

 

dn: cn=tom,ou=sudoers,dc=lansgg,dc=com

objectClass: top

objectClass: sudoRole

cn: tom

sudoCommand: ALL

sudoHost: ALL

sudoOption: !authenticate

sudoRunAsUser: ALL

sudoUser: tom


3.导入

ldapadd -x -w adminpw -D "cn=admin,dc=lansgg,dc=com" -f sudo.ldif


4.客户端编辑

vim /etc/sudo-ldap.conf

55 #uri ldap://ldapserver

56 uri ldap://192.168.28.139

63 #sudoers_base ou=SUDOers,dc=example,dc=com

64 sudoers_base ou=sudoers,dc=lansgg,dc=com

vim /etc/nsswitch.conf 

64 sudoers: ldap files



5.服务器测试

[root@master ~]# ssh [email protected]

reverse mapping checking getaddrinfo for bogon [192.168.28.143] failed - POSSIBLE BREAK-IN ATTEMPT!

[email protected]'s password: 

Last login: Sat Aug 23 23:15:27 2014 from 192.168.28.150

[tom@c1 ~]$ sudo su

[root@c1 tom]#



url:https://blog.51cto.com/laoguang/1636273

三. LDAP负责sudo

3.1 拷贝sudo schema,centos版本不一样,可能sudo的版本不是1.8.6,其他的也可以

# cp /usr/share/doc/sudo-1.8.6p3/schema.OpenLDAP /etc/openldap/schema/sudo.schema

3.2 修改文件导入schema# vim /etc/openldap/slapd.conf 

  include         /etc/openldap/schema/sudo.schema

3.3 重新生成配置文件,重启slapd

# rm -rf /etc/openldap/slapd.d/*

# slaptest -f /etc/openldap/slapd.conf -F /etc/openldap/slapd.d

# chown -R ldap:ldap /etc/openldap/slapd.d/* 

# service slapd restart

3.4 导入sudo.ldif到ldapserver

# ldapadd -x -W -D "cn=admin,dc=jumpserver,dc=org" -f sudo.ldif

  #说明:将sudo.ldif中的dc=jumpserver,dc=org换作你的baseDN

3.5 testserver设置sudo使用ldap

  说明: centos6上sudo-1.7.4p5的使用的ldap配置文件是 /etc/sudo-ldap.conf,sudo版本不同使用的配置文件可能也有所不同,sudo -V | grep 'ldap.conf' 查看

# sudo -V | grep 'ldap.conf'   

...

ldap.conf path: /etc/sudo-ldap.conf  # 已知有的版本是 /etc/nslcd.conf,下面应该做出对应改变...

--- CentOS6 ---

# echo -e "uri ldap://192.168.20.130\nSudoers_base ou=Sudoers,dc=jumpserver,dc=org" > /etc/sudo-ldap.conf 

# echo "Sudoers: files ldap" >>  /etc/nsswitch.conf

--- CentOS5 ---

# echo "Sudoers_base ou=Sudoers,dc=jumpserver,dc=org" >> /etc/ldap.conf

# echo "Sudoers: files ldap" >> /etc/nsswitch.conf

3.6 测试sudo

# ssh [email protected]

# sudo su 

  #说明:密码是testuser123,sudo su如果不提示输入密码,则成功