aquaballoon

LDAP Server

Jun 22nd, 2011
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 8.38 KB | None | 0 0
  1. Installation
  2.  
  3. $ sudo apt-get --yes install slapd ldap-utils
  4.  
  5.  
  6. Configuration
  7.  
  8. $ sudo gedit /etc/default/slapd
  9. SLAPD_CONF=/etc/ldap/slapd.conf
  10.  
  11. $ sudo rm -r /etc/ldap/slapd.d
  12.  
  13. $ sudo gedit /etc/ldap/slapd.conf
  14. # This is the main slapd configuration file. See slapd.conf for more
  15. # info on the configuration options.
  16.  
  17. #######################################################################
  18. # Global Directives:
  19.  
  20. # Features to permit
  21. # allow bind_v2
  22.  
  23. # Schema and objectClass definitions
  24. include         /etc/ldap/schema/core.schema
  25. include         /etc/ldap/schema/cosine.schema
  26. include         /etc/ldap/schema/nis.schema
  27. include         /etc/ldap/schema/inetorgperson.schema
  28.  
  29. # Where the pid file is put. The init.d script
  30. # will not stop the server if you change this.
  31. pidfile         /var/run/slapd/slapd.pid
  32.  
  33. # List of arguments that were passed to the server
  34. argsfile        /var/run/slapd/slapd.args
  35.  
  36. # Read slapd.conf(5) for possible values
  37. loglevel        none
  38.  
  39. # Where the dynamically loaded modules are stored
  40. modulepath    /usr/lib/ldap
  41. moduleload    back_hdb
  42.  
  43. # The maximum number of entries that is returned for a search operation
  44. sizelimit 500
  45.  
  46. # The tool-threads parameter sets the actual amount of cpu's that is used
  47. # for indexing.
  48. tool-threads 1
  49.  
  50. #######################################################################
  51. # Specific Backend Directives for hdb:
  52. # Backend specific directives apply to this backend until another
  53. # 'backend' directive occurs
  54. backend        hdb
  55.  
  56. #######################################################################
  57. # Specific Backend Directives for 'other':
  58. # Backend specific directives apply to this backend until another
  59. # 'backend' directive occurs
  60. #backend        <other>
  61. database config
  62. #######################################################################
  63. # Specific Directives for database #1, of type hdb:
  64. # Database specific directives apply to this databasse until another
  65. # 'database' directive occurs
  66. database        hdb
  67.  
  68. # The base of your directory in database #1
  69. suffix  "dc=linuxtest,dc=huree"
  70.  
  71. # rootdn directive for specifying a superuser on the database. This is needed
  72. # for syncrepl.
  73. rootdn  "cn=admin,dc=linuxtest,dc=huree"
  74. rootpw  abc123
  75.  
  76. # Where the database file are physically stored for database #1
  77. directory       "/var/lib/ldap"
  78.  
  79. # The dbconfig settings are used to generate a DB_CONFIG file the first
  80. # time slapd starts.  They do NOT override existing an existing DB_CONFIG
  81. # file.  You should therefore change these settings in DB_CONFIG directly
  82. # or remove DB_CONFIG and restart slapd for changes to take effect.
  83.  
  84. # For the Debian package we use 2MB as default but be sure to update this
  85. # value if you have plenty of RAM
  86. dbconfig set_cachesize 0 2097152 0
  87.  
  88. # Sven Hartge reported that he had to set this value incredibly high
  89. # to get slapd running at all. See http://bugs.debian.org/303057 for more
  90. # information.
  91.  
  92. # Number of objects that can be locked at the same time.
  93. dbconfig set_lk_max_objects 1500
  94. # Number of locks (both requested and granted)
  95. dbconfig set_lk_max_locks 1500
  96. # Number of lockers
  97. dbconfig set_lk_max_lockers 1500
  98.  
  99. # Indexing options for database #1
  100. index           objectClass eq
  101.  
  102. # Save the time that the entry gets modified, for database #1
  103. lastmod         on
  104.  
  105. # Checkpoint the BerkeleyDB database periodically in case of system
  106. # failure and to speed slapd shutdown.
  107. checkpoint      512 30
  108.  
  109. # Where to store the replica logs for database #1
  110. # replogfile    /var/lib/ldap/replog
  111.  
  112. # The userPassword by default can be changed
  113. # by the entry owning it if they are authenticated.
  114. # Others should not be able to see it, except the
  115. # admin entry below
  116. # These access lines apply to database #1 only
  117. # acl specific for phamm
  118.  
  119. access to attrs=userPassword,shadowLastChange
  120.     by dn="cn=admin,dc=linuxtest,dc=huree"  write
  121.         by anonymous auth
  122.         by self write
  123.         by * none
  124.  
  125. access to *
  126.        by dn="cn=admin,dc=linuxtest,dc=huree" write    
  127.         by * read
  128.  
  129. access to dn.base="" by * read
  130.  
  131. # For Netscape Roaming support, each user gets a roaming
  132. # profile for which they have write access to
  133. #access to dn=".*,ou=Roaming,o=morsnet"
  134. #        by dn="cn=admin,dc=yourdomain,dc=tld" write
  135. #        by dnattr=owner write
  136.  
  137. #######################################################################
  138. # Specific Directives for database #2, of type 'other' (can be hdb too):
  139. # Database specific directives apply to this databasse until another
  140. # 'database' directive occurs
  141. #database        <other>
  142.  
  143. # The base of your directory for database #2
  144. #suffix        "dc=debian,dc=org"
  145.  
  146.  
  147.  
  148. Populating LDAP
  149.  
  150. $ sudo gedit /etc/ldap/init.ldif
  151. dn: dc=linuxtest,dc=huree      
  152. objectClass: dcObject
  153. objectClass: organizationalUnit
  154. dc: linuxtest
  155. ou: My Example File
  156.  
  157. dn: cn=admin,dc=linuxtest,dc=huree
  158. objectClass: simpleSecurityObject
  159. objectClass: organizationalRole
  160. cn: admin
  161. description: LDAP administrator
  162. userPassword: abc123
  163.  
  164. $ sudo /etc/init.d/slapd stop
  165.  
  166. $ sudo rm -rf /var/lib/ldap/*
  167.  
  168. $ sudo slapadd -v -l /etc/ldap/init.ldif
  169.  
  170. $ sudo chown -R openldap:openldap /var/lib/ldap
  171.  
  172. $ sudo /etc/init.d/slapd start
  173.  
  174. $ ldapsearch -xLLL -b "dc=linuxtest,dc=huree"
  175.  
  176.  
  177. LDAP Authentication
  178.  
  179. $ sudo apt-get install libpam-ldap libnss-ldap nss-updatedb libnss-db ldap-auth-client ldap-auth-config
  180.  
  181. $ sudo gedit /etc/ldap/ldap.conf
  182. host 127.0.0.1
  183.  
  184. BASE dc=linuxtest,dc=huree
  185. URI ldap://linuxtest.huree
  186.  
  187. rootbinddn cn=admin,dc=linuxtest,dc=huree
  188. bind_policy soft
  189.  
  190. $ sudo gedit /etc/nsswitch.conf
  191. passwd: files ldap
  192. group:  files ldap
  193. shadow: files ldap
  194.  
  195. $ sudo gedit /etc/pam.d/common-account
  196. account sufficient pam_ldap.so
  197. account required pam_unix.so
  198.  
  199. $ sudo gedit /etc/pam.d/common-session
  200. session sufficient pam_ldap.so
  201. session required pam_unix.so
  202.  
  203. $ sudo gedit /etc/pam.d/common-auth
  204. auth sufficient pam_ldap.so
  205. auth required pam_unix.so nullok_secure use_first_pass
  206.  
  207. $ sudo gedit /etc/pam.d/common-password
  208. password sufficient pam_ldap.so
  209. password required pam_unix.so nullok obscure min=4 max=8 md5
  210.  
  211.  
  212. Creating User
  213.  
  214. $sudo mkdir /export/banana
  215. $sudo chown -R banana.users /export/banana
  216. $sudo chmod -R 0700 /export/banana
  217.  
  218.  
  219. Backup LDAP database
  220.  
  221. $ sudo /usr/sbin/slapcat -v -n 1 -l /etc/ldap/backup.ldif
  222.  
  223.  
  224. Restore LDAP database
  225.  
  226. $ sudo /etc/init.d/slapd stop
  227.  
  228. $ sudo rm -rf /var/lib/ldap/*
  229.  
  230. $ sudo slapadd -v -l /etc/ldap/backup.ldif
  231.  
  232. $ sudo chown -R openldap:openldap /var/lib/ldap
  233.  
  234. $ sudo /etc/init.d/slapd restart
  235.  
  236.  
  237. Creating LDAP database
  238.  
  239. $ sudo gedit /etc/ldap/init.ldif
  240. dn: dc=jason,dc=huree      
  241. objectClass: dcObject
  242. objectClass: organizationalUnit
  243. dc: jason
  244. ou: My Example File
  245.  
  246. dn: cn=admin,dc=jason,dc=huree
  247. objectClass: simpleSecurityObject
  248. objectClass: organizationalRole
  249. cn: admin
  250. description: LDAP administrator
  251. userPassword: ******
  252.  
  253. dn: dc=Users,dc=jason,dc=huree
  254. objectClass: domain
  255. dc: Users
  256.  
  257. dn: dc=Groups,dc=jason,dc=huree
  258. objectClass: domain
  259. dc: Groups
  260.  
  261. dn: uid=apple,dc=jason,dc=huree
  262. cn: apple
  263. uid: apple
  264. uidNumber: 1001
  265. loginShell: /bin/bash
  266. homeDirectory: /export/apple
  267. gidNumber: 100
  268. userPassword:
  269. objectClass: posixAccount
  270. objectClass: shadowAccount
  271. objectClass: person
  272. objectClass: inetOrgPerson
  273. gecos: apple
  274. sn: apple
  275.  
  276. dn: uid=apple,dc=Users,dc=jason,dc=huree
  277. cn: apple
  278. uid: apple
  279. uidNumber: 1001
  280. loginShell: /bin/bash
  281. homeDirectory: /export/apple
  282. gidNumber: 100
  283. userPassword:
  284. objectClass: posixAccount
  285. objectClass: shadowAccount
  286. objectClass: person
  287. objectClass: inetOrgPerson
  288. shadowLastChange: 15094
  289. gecos: apple
  290. sn: apple
  291.  
  292. dn: uid=banana,dc=jason,dc=huree
  293. cn: banana
  294. uid: banana
  295. uidNumber: 1002
  296. loginShell: /bin/bash
  297. homeDirectory: /export/banana
  298. gidNumber: 100
  299. userPassword:
  300. objectClass: posixAccount
  301. objectClass: shadowAccount
  302. objectClass: person
  303. objectClass: inetOrgPerson
  304. gecos: banana
  305. sn: banana
  306.  
  307. dn: uid=banana,dc=Users,dc=jason,dc=huree
  308. cn: banana
  309. uid: banana
  310. uidNumber: 1002
  311. loginShell: /bin/bash
  312. homeDirectory: /export/banana
  313. gidNumber: 100
  314. userPassword:
  315. objectClass: posixAccount
  316. objectClass: shadowAccount
  317. objectClass: person
  318. objectClass: inetOrgPerson
  319. shadowLastChange: 15094
  320. gecos: banana
  321. sn: banana
  322.  
  323.  
  324. $ sudo /etc/init.d/slapd stop
  325.  
  326. $ sudo rm -rf /var/lib/ldap/*
  327.  
  328. $ sudo slapadd -v -l /etc/ldap/init.ldif
  329.  
  330. $ chown -R openldap:openldap /var/lib/ldap
  331.  
  332. $ /etc/init.d/slapd restart
Advertisement
Add Comment
Please, Sign In to add comment