howtodownload

howtodownload
cach down
Hiển thị các bài đăng có nhãn ldap. Hiển thị tất cả bài đăng
Hiển thị các bài đăng có nhãn ldap. Hiển thị tất cả bài đăng

Thứ Sáu, 4 tháng 10, 2013

Cách xoá database của openldap

Vì một vài nguyên nhân nào đó mà bạn muốn xoá database cũ của ldap và cài mới nó thì bạn chỉ cần 3 bước đơn giản sau đây là bạn sẽ thành công.

Bước 1 : Stop dịch vụ LDAP lại :

service ldap stop
Bước 2 : bạn vào thư mục chứa DB của LDAP và xoá các database của LDAP đi.

rm -f /var/lib/ldap/*.*
Bước 3 : Start LDAP lên và tạo mới DB :

service ldap start
NOTE : các bạn chú ý là khi build lại DB thì nhớ chạy lệnh smbldap-populate nhé.không thì khi bạn tạo user không được đâu.

ERROR 

[root@alesi ~]# smbldap-groupadd test
Error looking for next uid in cn=NextFreeUnixId,dc=no-dns,dc=co,dc=uk:No such
object at /usr/lib/perl5/vendor_perl/5.8.8/smbldap_tools.pm line 1071
PS: cái này nghe có vẻ bình thường quá nhưng mình nghĩ có một số bạn khi muốn xoá nó đi lại chả biết cái nào là DB của nó mà xoá.chi biết nó nằm trong /var/lib/ldap/ thôi.nhỡ xoá nhầm thì nguy to.mình cũng từng gặp phải vấn đề này nên note lại cho các bạn cái này khi cần thì xem mà biết cách del DB.

Thứ Bảy, 14 tháng 9, 2013

Cấu hình dịch vụ mail postfix chứng thực LDAP

Postfix là một dịch vụ mail được coi là tốt nhất vì sự ổn định , khả năng chịu nhiều connection, và tính đơn giản gọn nhẹ của nó.Hầu hết các máy chủ mail tại Việt Nam đều sử dụng postfix.Hôm nay mình xin demo bài lab cấu hình postfix sử dụng user của ldap .


Bước 1 : Cấu hình OpenLdap

mình đã từng cấu hình openldap nên mình không nói lại về điều này nữa nhé.bạn có thể tham khảo qua link sau :

http://lunocio.blogspot.com/2013/09/cau-hinh-openldap-tren-centos.html


ở đây mình chỉ đổi tên domain abc.com thành dnson.local thôi nhá. . với các bạn thì cái này không quan trọng lắm vì domain của mình chẳng ảnh hưởng gì tới bạn cả.

Bước 2 : Cài đặt và cấu hình Postfix

Cài đặt 

yum install -y postfix dovecot squirrelmail

Cấu hình :

bạn mở file cấu hình của postfix ra bằng lệnh

vim /etc/postfix/main.cf

và sửa các dòng sau.


#tên máy chủ gởi mail
70 myhostname = mail.dnson.local
#domain dùng để gởi nhận mail
77 mydomain = dnson.local
#giữ nguyên thông tin domain khi gởi
93 myorigin = $mydomain
#tất cả các interface nhận mail
110 inet_interfaces = all
#chỉ nhận mail đế domain của tôi
157 mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
#các IP được phép relay qua server mail
255 mynetworks = 10.10.10.0/24 , 127.0.0.0/8


tiếp đó bạn mở file cấu hình dovecot ra bằng lệnh

vim /etc/dovecot.conf

 và sửa các dòng sau :


45   passdb ldap {
46     # Path for LDAP configuration file, see doc/dovecot-ldap-example.conf
47     args = /etc/dovecot-ldap.conf
48   }


bây giờ bạn tạo file dùng để chứng thực ldap nhé

bạn dùng lệnh vim tạo file dovecot-ldap.conf

vim /etc/dovecot-ldap.conf


#IP 
mail serverhosts = 10.10.10.254 
base = dc=dnson.local,dc=localldap_version = 3


bạn sửa lại file config.php của squirrelmail để gởi mail có domain dnson.local chứ không phải là localhost

vim /etc/squirrelmail/config.php

30 $domain                 = 'dnson.local';
31 $imapServerAddress      = 'mail.dnson.local';


bạn có thể cài gói change_ldappass để cho phép user change password ngay trên webmail.

giờ bạn qua bên ldap server và sửa file slapd.conf

vim /etc/openldap/slapd.conf

 79 # rootdn can always read and write EVERYTHING!
 80 access to * by * write //[COLOR="#FF0000"]bạn thêm dòng này vào[/COLOR]
 81 #######################################################################
 82 # ldbm and/or bdb database definitions


Vậy là coi như đã xong rồi. giờ thì bật postfix và dovecot lên rồi dùng một máy XP để test thôi.


service postfix start
service dovecot start

Cấu hình OpenLDAP trên Centos

Bạn đã nghe đến openldap bao giờ chưa ? Openldap thực ra là một database dùng để lưu trữ và chứng thực người dùng .Nói nôm na nó cứ như là active direcroy bên windows ấy mà.

Nói đến đây chắc bạn đã hình dung được công dụng của openldap trong thực tế rồi chứ gì. Người ta sử dụng openldap để làm  database lưu user chứng thực cho user join và logon domain , chứng thực user sử dụng các dịch vụ như web , ftp ,.......vv.

Khỏi nói nhiều chúng ta vào làm luôn một phát nhỉ ?

Chuẩn bị :

chỉ cần 1 máy thôi là đủ.ở đây mình dùng Centos là Openldap master.

IP : 10.10.10.10

Cài đặt :

yum install openldap* -y

Cấu hình :

Bước 1 :

Tạo mật khẩu cho user root LDAP. (bạn nhập mật khẩu vào sẽ ra được một đoạn mã và bạn coppy đoạn mã đó vào nhé.)

slappasswd


(bạn nhập mật khẩu ví dụ ở đây là 123 )


Bước 2 : mở file cấu hình /etc/openldap/slapd.conf và chỉnh lại các dòng sau theo ý bạn nha.

vim /etc/openldap/slapd.conf


Giải thích một chút nha:

Manager ở đây như là root vậy.

dc=tên domain của bạn

rootpw=nhập cái mã mà bạn coppy từ dòng lệnh slappaswd vào đây.

Bước 3 : mở file cấu hình /etc/openldap/ldap.conf và chỉnh lại các dòng sau.

vim /etc/openldap/ldap.conf


Giải thích một chút nhé ;

389 : là port của ldap

10.10.10.10 là ip của server

Bước 4 : Cấu hình file chuyển đổi lưu trữ /etc/nsswitch.conf

vim /etc/nsswitch.conf


Giải thích đoạn này tý :

thêm ldap vào là để chuyển đổi việc truy vấn và lưu trữ mật khẩu và tên người dùng ,tên group  sang cho ldap quản lý.nếu không thì hệ thống sẽ chỉ truy vấn và lưu trữ trên các file mặc định trong /etc

Bước 5 : coppy file cấu hình mẫu của ldap vào nơi chứa database của ldap.

cp /etc/openldap/DB_CONFIG.example /var/lib/ldap/DB_CONFIG

Bước 6 : Khởi tạo ldap và cho ldap start cùng hệ thống

service ldap start
chkconfig ldap on

Bước 7 : Tạo database cho ldap từ file /etc/passwd

cd /usr/share/openldap/migration

   -sửa file migrate_common.ph

vim migrate_common.ph


./migrate_base.pl > /root/base.ldif
   -Trích xuất user hệ thống ra 1 file alluser.ldif

./migrate_passwd.pl /etc/passwd > /root/alluser.ldif
  -Lấy user hệ thống add vào ldap

ldapadd -c -x -D "cn=Manager,dc=abc,dc=com" -W -f /root/base.ldif

https://lh6.googleusercontent.com/-O-0AwXxTWyk/T8sHbrAUmYI/AAAAAAAABIg/t33E2gaqQF0/s779/conmotit_6.jpg

(bạn nhập mật khẩu mà bạn đã gõ ở lệnh slappasswd nhé)

ldapadd -c -x -D "cn=Manager,dc=abc,dc=com" -W -f /root/alluser.ldif


Bước 8 : Bây giờ coi như là đã xong xuôi rồi.bạn có thể dùng lệnh sau để kiểm tra nhé

- kiểm tra tất cả user trên ldap server bằng lệnh

slapcat 

 nếu trước khi thực hiện bài lab này mà bạn đã tạo sẵn một user thì khi slapcat bạn sẽ thấy user đó.

Bước  9 : tạo user.

-tạo một user trên hệ thống và đưa vào ldap. user này có tên là ldapuser và thuộc nhóm users

useradd -g users ldapuser
passwd ldapuser

-đưa thông tin của ldapuser từ /etc/passwd vào file /root/a.info

grep "ldapuser" /etc/passwd | tee /root/a.info

-đưa user chứa trong file a.info vào kiến trúc ldap.

./migrate_passwd.pl /root/a.info > /root/alluser.ldif

-đưa user vào trong ldap

ldapadd -c -x -D "cn=Manager,dc=abc,dc=com" -W -f /root/alluser.ldif

 -kiểm tra thông tin về user xem nó đã được tạo ra như chúng ta đã làm chưa bằng lệnh

finger


Vậy là xong rồi đó.

Các bạn có thể dùng một tool chạy trên windows để quản lý ldap đó là "LDAP ADMIN".

Giao diện đơn giản và dễ sử dụng nên mình không demo cái này nữa nha các bạn.Phải tự nghiên cứu mới khoái chứ chỉ ra hết thì còn gì thú vị nữa phải không ??

Thứ Sáu, 13 tháng 9, 2013

Cấu hình SAMBA + LDAP trên Centos (Phần 5) - Mở rộng

Phần mở rộng

Trong phần mở rộng này mình sẽ cố gắng đưa thêm các bước setup cho một domain samba ldaphoàn chỉnh gồm một số policy hay deploy một software....vv.Các phần khác mình sẽ cập nhật thêm ở phía dưới bài này....

- Yêu cầu user đặt password thấp nhất là 10 ký tự :

pdbedit -P "min password length" -C 10



- Yêu cầu user phải thay đổi password khi logon :

 pdbedit -P "user must logon to change password" -C 2


- User phải change password trong lần đầu tiên logon : (ví dụ user là kiemtra)

net sam set pwdmustchangenow kiemtra yes




Deploy Software

Đây là phần mà mình biết có nhiều mem trong diễn đàn chờ mong và có lẽ cũng là điều mà hầu như những ai đã và đang học linux không nghĩ đến trong đó có cả mình.Cảm ơn một member đã nhắc mình vấn đề này để rồi sau một thời gian nghiên cứu mình đã tìm ra.Và mình nghĩ có lẽ vấn đề này đến thời điểm hiện tại chỉ có mỗi mình mình viết bài về deploy software trên hệ thống linux.(Bới tung nước ngoài còn chẳng thấy ai viết nữa là.)

Để triển khai được phần mềm trên linux domain thì bạn phải sử dụng tiện ích WPKG.

Trang chủ của nó : http://www.wpkg.org

Để download bạn cần vào trang sau : http://wpkg.org/Download

Ở đây có nhiều thứ để bạn có thể nghiên cứu đấy.Cái file zip đầu tiên ở phần stable là dành cho server của bạn.Cái WPKG client thì dành cho máy client. Tức là giống như bạn dùng adminpak ấy mà.WPKG Web Interface là cấu hình trên giao diện web.Bạn có thể lên  http://www.migee.com/2010/06/25/wpkg-and-wpkgexpress-suse-linux-install-guide-pictures-aplenty/  để nghiên cứu cách sử dụng. Dùng giao diện web thì khá hay và trực quan nhưng mình vẫn thích dùng loại cổ điển hơn và thực ra mình cũng chỉ mới nghiên cứu tới đó.Ngoài ra bạn có thể xài WPKG Group Policy để vọc nha.Bạn nào nghiên cứu cách khác thì post lên nha.

Ở đây mình dùng bản stable : http://wpkg.org/files/stable/1.3.x/wpkg-1.3.0-bin.zip

Nếu server của bạn có mạng thì bạn có thể chạy lệnh sau để download về.

wget http://wpkg.org/files/stable/1.3.x/wpkg-1.3.0-bin.zip

Việc cấu hình WPKG chỉ thực hiện trên  server thôi nhá.

Sau khi download về bạn gõ lệnh unzip để giải nén file zip bạn đã down về.

unzip wpkg-1.3.0-bin.zip

Sau khi giải nén xong bạn coppy thư mục vừa giải nén ra thư mục gốc.

cp wpkg /wpkg

và phân quyền full cho thư mục này.

chmod 777 -R /wpkg

sau đó bạn cd vào thư mục này nhé.

cd /wpkg

Ở trong thư mục này bạn chỉ cần quan tâm tới 3 file sau để sửa thôi nhá : hosts.xml , package.xml , profiles.xml

Đầu tiên bạn dùng lệnh vi hoặc lệnh vim để edit file như sau :

vim hosts.xml

<?xml version="1.0" encoding="UTF-8"?>
<hosts:wpkg xmlns:hosts="http://www.wpkg.org/hosts" xmlns:wpkg="http://www.wpkg.org/wpkg"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.wpkg.org/hosts xsd/hosts.xsd ">
        <!--
                Specifies a match for host name "hostname" and assigns profile "custom"
                to this host.
        -->
        <host name="ad.dnson.local" profile-id="kiemtra">
        </host>
        <host name=".+" profile-id="other" />
</hosts:wpkg>


Ở đây mình giải thích chút như sau :

Dòng <host name="ad.dnson.local" profile-id="kiemtra"> bạn thay ad.dnson.local bằng hostname server của bạn.Để xem hostname của server thì bạn gõ lệnh hostname. Mục profile-id bạn thay "kiemtra" một tên nào đó bạn muốn.

Nếu bạn muốn sử dụng nhiều hơn 1 profile thì bạn dùng cú pháp sau

<host name="host1" profile-id="custom1" >
  <profile id="addons1"/>
  <profile id="addons2"/>
</host>

vim packages.xml

<?xml version="1.0" encoding="UTF-8"?>
<packages>
<package
        id="ccleaner"
        name="CCleaner"
        revision="3.24.1850"
        reboot="false"
        priority="1090">
        <variable name="version" value="3.24" />
        <check type="uninstall" condition="exists" path="CCleaner" />
        <check type="file" condition="versiongreaterorequal" path="%PROGRAMFILES%\CCleaner\CCleaner.exe" value="3.24.1850"/>
        <install cmd='\\\\10.10.10.1\wpkg\ccleaner\ccsetup324.exe /S' />
        <upgrade cmd='\\\\10.10.10.1\wpkg\ccleaner\ccsetup324.exe /S' />
        <remove cmd='"%ProgramFiles%\CCleaner\uninst.exe" /S' />
</package>
</packages>

Giải thích :

id="ccleaner" : mã gói cài

name="CCleaner" : Tên gói cài đặt

revision="3.24.1850" : phiên bản phần mềm ccleaner

reboot="false" : khởi động thất bại

priority="1090" : mức độ ưu tiên

<variable name="version" value="3.24" /> : dòng value là phiên bản

<check type="uninstall" condition="exists" path="CCleaner" /> : chưa giải thích được

<check type="file" condition="versiongreaterorequal" path="%PROGRAMFILES%\CCleaner\CCleaner.exe" value="3.24.1850"/> : path là đường dẫn sẽ cài đặt trên máy client. còn value thì là phiên bản phần mềm.

<install cmd='\\\\10.10.10.1\wpkg\ccleaner\ccsetup324.exe /S' /> : Đây là đường dẫn chứa file cài đặt ccleaner trên server.Mình thì tạo 1 file tên ccleaner trong thư mục wpkg để chứa phần mềm cần deploy.

<upgrade cmd='\\\\10.10.10.1\wpkg\ccleaner\ccsetup324.exe /S' /> : cái này là đường dẫn chứa file để nâng cấp.ví dụ bạn đang deploy ver 1 và giờ ra ver 2 thì bạn đưa file ver vào thư mục và trỏ đường dẫn tới.

<remove cmd='"%ProgramFiles%\CCleaner\uninst.exe" /S' /> : gỡ cài đặt phần mềm.

Để deploy một phần mềm thì WPKG sử dụng lệnh cmd trên máy client để chạy. Tham số /S là để deploy phần mềm ở chế độ im lặng.Điều này có nghĩa là bạn sẽ không thấy quá trình cài đặt diễn ra ở màn hình đăng nhập.Nếu bạn bỏ tham số này thì khi cài vào bạn sẽ thấy nó bắt bạn chờ để nó install.Giống như điều mà bạn thấy khi bạn deploy trên hệ thống windows.

vim profiles.xml

<?xml version="1.0" encoding="UTF-8"?>
<profiles:profiles xmlns:profiles="http://www.wpkg.org/profiles"
        xmlns:wpkg="http://www.wpkg.org/wpkg" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.wpkg.org/profiles xsd/profiles.xsd ">
        <!--
                Default set of software to be assigned to all hosts.
        -->
        <profile id="kiemtra">
                <package package-id="ccleaner" />
        </profile>
</profiles:profiles>


Giải thích :

<profile id="kiemtra"> : cái dòng này giống với trong file hosts.xml

<package package-id="ccleaner" /> : package-id là giống với đoạn <package id="ccleaner" trong file packages.xml

Giờ trong thư mục /wpkg bạn tạo thư mục ccleaner nhé.

mkdir /wpkg/ccleaner

Bạn di chuyển vào trong thư mục bạn vừa tạo (ccleaner) để down phần mềm ccleaner về.

cd /wpkg/ccleaner

wget http://software-files-a.cnet.com/s/software/12/80/04/63/ccsetup324.exe?token=1352029193_b3bd187a14a183cb3f6edab884d7a7ff&lop=link&ptype=3001&ontid=18512&siteId=4&edId=3&spi=6203e1f74a225a810cfedd11ac3a0f6c&pid=12800463&psid=10315544&fileName=ccsetup324.exe

Hiện tại thời điểm viết bài thì bản ccleaner free có phiên bản là 3.24.1850

Cuối cùng bạn gõ lệnh sau để chạy script file nhé.

script /wpkg/wpkg.js

Giờ bạn qua máy client XP để test nhé.



Note : Bạn có thể vào link sau để xem các phần mềm có thể deploy

http://wpkg.org/Category:Silent_Installers

Cấu hình SAMBA + LDAP trên Centos (phần 4)

Bây giờ bạn  gõ lệnh

cd /usr/share/openldap/migration

Bạn mở file bằng lệnh

vim migrate_common.ph

Và tìm đến chỗ


# Default DNS domain
$DEFAULT_MAIL_DOMAIN = "dnson.local";
sửa lại cho giống domain của bạn
# Default base 
$DEFAULT_BASE = "dc=dnson,dc=local";sửa lại cho giống domain của bạn



Bạn gõ tiếp các lệnh sau.

./migrate_base.pl > base.ldif
./migrate_passwd.pl passwd > alluser.ldif
./migrate_group.pl group > group.ldif
ldapadd -c -x -D "cn=Manager,dc=dnson,dc=local" -W -f base.ldif
ldapadd -c -x -D "cn=Manager,dc=dnson,dc=local" -W -f alluser.ldif
ldapadd -c -x -D "cn=Manager,dc=dnson,dc=local" -W -f group.ldif

Bạn nhập mật khẩu cho 3 lệnh trên là 123456

Giải thích một chút ở đây nhé :

-x là chỉ định không sử dụng sasl
-W nhập mật khẩu
-D được xác định ai là administrator
-f xác định ldapadd tìm dữ liệu ở đâu

Bạn gõ tiếp lệnh sau nhé

smbldap-populate



vì mình chạy lại lệnh này nên nó kêu là already exist còn các bạn làm mới thì nó sẽ add vào cho bạn.

Tạo user cho domain member.

smbldap-useradd -a -G "Domain Users" -m -s /bin/bash -d /home/kiemtra -F "" -P kiemtra

Tạo mật khẩu cho user vừa rồi.

smbldap-passwd u1

Bước 4.Hoàn tất.

Tắt tường lửa.

service iptables stop
chkconfig iptables off

Tắt SElinux

setenforce permissive

Khởi động lại các dịch vụ samba , dns , openldap .

service smb restart
service nmb restart
service ldap restart
service named restart

Qua máy client join như join vào domain windows thôi nhé.

Bạn logon administrator và chỉnh gpedit.msc như sau nha rồi hãy join nhé.



Chú ý : nếu bạn join mà gặp lỗi sau :

the following error occurred attempting to join the domain access denied

thì bạn cần xem lại mật khẩu của root và mật khẩu của user quản lý samba ldap.nó phải là giống nhau.như mình nói đấy.mật khẩu giống nhau cả loạt thì không lỗi gì đâu.đây là kinh nghiệm của mình khi cấu hình bài lab này.

ROAMING PROFILE


Mình tạo 1 user có tên là kiemtra và logon vào domain.Sau đó tạo 1 folder trên desktop có tên dài ngoằng là "dddddddddddddddd" .

smbldap-useradd -a -G "Domain Users" -m -s /bin/bash -d /home/kiemtra -F "" -P kiemtra



sau đó logoff và lên server kiểm tra sẽ thấy folder này.


Link tham khảo roaming profile :

http://www.samba.org/samba/docs/man/Samba-HOWTO-Collection/ProfileMgmt.html

Bạn nào thấy khó quá thì cứ down file cấu hình về mà nghịch nhé.

Cấu hình SAMBA + LDAP trên centos (phần 3)

Cấu hình SAMBA và SMBLDAP-TOOLS.

Bạn sửa file smbldap_bind.conf bằng lệnh 


vim /etc/smbldap-tools/smbldap_bind.conf


slaveDN="cn=Manager,dc=dnson,dc=local"slavePw="123456"masterDN="cn=Manager,dc=dnson,dc=local"masterPw="123"


Sau đó bạn lại sửa file smbldap.conf bằng lệnh 


vim /etc/smbldap-tools/smbldap.conf


sambaDomain="dnson.local"
################################################################################ LDAP Configuration###############################################################################
# Notes: to use to dual ldap servers backend for Samba, you must patch# Samba with the dual-head patch from IDEALX. If not using this patch# just use the same server for slaveLDAP and masterLDAP.# Those two servers declarations can also be used when you have# . one master LDAP server where all writing operations must be done# . one slave LDAP server where all reading operations must be done#   (typically a replication directory)
# Slave LDAP server# Ex: slaveLDAP=127.0.0.1# If not defined, parameter is set to "127.0.0.1"slaveLDAP="slave.dnson.local"
# Slave LDAP port# If not defined, parameter is set to "389"slavePort="389"
# Master LDAP server: needed for write operations# Ex: masterLDAP=127.0.0.1# If not defined, parameter is set to "127.0.0.1"masterLDAP="ad.dnson.local"
# Master LDAP port# If not defined, parameter is set to "389"masterPort="389"
# Use TLS for LDAP# If set to 1, this option will use start_tls for connection# (you should also used the port 389)# If not defined, parameter is set to "1"ldapTLS="0"
# How to verify the server's certificate (none, optional or require)# see "man Net::LDAP" in start_tls section for more detailsverify="none"
# CA certificate# see "man Net::LDAP" in start_tls section for more detailscafile=""
# certificate to use to connect to the ldap server# see "man Net::LDAP" in start_tls section for more detailsclientcert=""
# key certificate to use to connect to the ldap server# see "man Net::LDAP" in start_tls section for more detailsclientkey=""
# LDAP Suffix# Ex: suffix=dc=IDEALX,dc=ORGsuffix="dc=dnson,dc=local"
# Where are stored Users# Ex: usersdn="ou=Users,dc=IDEALX,dc=ORG"# Warning: if 'suffix' is not set here, you must set the full dn for usersdnusersdn="ou=Users,${suffix}"
# Where are stored Computers# Ex: computersdn="ou=Computers,dc=IDEALX,dc=ORG"# Warning: if 'suffix' is not set here, you must set the full dn for computersdncomputersdn="ou=Computers,${suffix}"
# Where are stored Groups# Ex: groupsdn="ou=Groups,dc=IDEALX,dc=ORG"# Warning: if 'suffix' is not set here, you must set the full dn for groupsdngroupsdn="ou=Groups,${suffix}"
# Where are stored Idmap entries (used if samba is a domain member server)# Ex: groupsdn="ou=Idmap,dc=IDEALX,dc=ORG"# Warning: if 'suffix' is not set here, you must set the full dn for idmapdnidmapdn="ou=Idmap,${suffix}"
# Where to store next uidNumber and gidNumber available for new users and groups# If not defined, entries are stored in sambaDomainName object.# Ex: sambaUnixIdPooldn="sambaDomainName=${sambaDomain},${suffix}"# Ex: sambaUnixIdPooldn="cn=NextFreeUnixId,${suffix}"sambaUnixIdPooldn="sambaDomainName=${sambaDomain},${suffix}"
# Default scope Usedscope="sub"
# Unix password encryption (CRYPT, MD5, SMD5, SSHA, SHA, CLEARTEXT)hash_encrypt="SSHA"
# if hash_encrypt is set to CRYPT, you may set a salt format.# default is "%s", but many systems will generate MD5 hashed# passwords if you use "$1$%.8s". This parameter is optional!crypt_salt_format=""
################################################################################ Unix Accounts Configuration###############################################################################
# Login defs# Default Login Shell# Ex: userLoginShell="/bin/bash" userLoginShell="/bin/bash"
# Home directory# Ex: userHome="/home/%U"userHome="/home/%U"
# Default mode used for user homeDirectoryuserHomeDirectoryMode="700"
# GecosuserGecos="System User"
# Default User (POSIX and Samba) GIDdefaultUserGid="513"
# Default Computer (Samba) GIDdefaultComputerGid="515"
# Skel dirskeletonDir="/etc/skel"
# Default password validation time (time in days) Comment the next line if# you don't want password to be enable for defaultMaxPasswordAge days (be# careful to the sambaPwdMustChange attribute's value)defaultMaxPasswordAge="45"
################################################################################ SAMBA Configuration###############################################################################
# The UNC path to home drives location (%U username substitution)# Just set it to a null string if you want to use the smb.conf 'logon home'# directive and/or disable roaming profiles# Ex: userSmbHome="\\PDC-SMB3\%U"userSmbHome="\\10.10.10.1\%U"
# The UNC path to profiles locations (%U username substitution)# Just set it to a null string if you want to use the smb.conf 'logon path'# directive and/or disable roaming profiles# Ex: userProfile="\\PDC-SMB3\profiles\%U"userProfile="\\10.10.10.1\profiles\%U"
# The default Home Drive Letter mapping# (will be automatically mapped at logon time if home directory exist)# Ex: userHomeDrive="H:"userHomeDrive="H:"
# The default user netlogon script name (%U username substitution)# if not used, will be automatically username.cmd# make sure script file is edited under dos# Ex: userScript="startup.cmd" # make sure script file is edited under dosuserScript="logon.bat"# Domain appended to the users "mail"-attribute# when smbldap-useradd -M is used# Ex: mailDomain="idealx.com"mailDomain="dnson.local"
################################################################################ SMBLDAP-TOOLS Configuration (default are ok for a RedHat)###############################################################################
# Allows not to use smbpasswd (if with_smbpasswd="0" in smbldap.conf) but# prefer Crypt::SmbHash librarywith_smbpasswd="0"smbpasswd="/usr/bin/smbpasswd"
# Allows not to use slappasswd (if with_slappasswd="0" in smbldap.conf)# but prefer Crypt:: librarieswith_slappasswd="0"slappasswd="/usr/sbin/slappasswd"
# comment out the following line to get rid of the default banner# no_banner="1"                                                        


Bạn dùng lệnh 


mv /etc/samba/smb.conf /etc/samba/smb.conf.backup

để đổi tên file cấu hình samba đề phòng file cấu hình mới có hư thì dùng lại file này.

Bạn gõ lệnh 


cp /usr/share/doc/smbldap-tools-0.9.6/smb.conf /etc/samba/

để coppy file cấu hình mới.cái file này dùng để cấu hình samba ldap đó.

Bạn mở file này lên bằng lệnh 


vim /etc/samba/smb.conf

và sửa lại như sau.


[global]
        ldap ssl = No
        nt acl support = No
        socket options = TCP_NODELAY SO_RCVBUF=8192 SO_SNDBUF=8192
        workgroup = dnson.local đây là cái mà ta nhập domain bên client để join
        realm = dnson.local
        netbios name = ldap
        security = user
        enable privileges = yes
        server string = Samba Server %v
        encrypt passwords = Yes
        interfaces = eth0
        bind interfaces only = yes
       username map = /etc/samba/smbusers
        unix password sync = yes
        ldap passwd sync = Yes
        passwd program = /usr/sbin/smbldap-passwd -u "%u"
        passwd chat = "Changing *\nNew password*" %n\n "*Retype new password*" %n\n"

        log level = 1
        syslog = 0
        log file = /var/log/samba/log.%U
        max log size = 100000
        time server = Yes
        smb ports = 139 445
        socket options = TCP_NODELAY SO_RCVBUF=8192 SO_SNDBUF=8192
        mangling method = hash2
        Dos charset = 850
        Unix charset = ISO8859-1

        logon script = logon.bat
        logon drive = H:
        logon home = \\%L\%U
        logon path = \\%L\profiles\%U

        domain logons = Yes
        domain master = Yes
        os level = 65
        preferred master = Yes
        wins support = yes
        passdb backend = ldapsam:ldap://10.10.10.1/
        ldap admin dn = cn=Manager,dc=dnson,dc=local
 ldap suffix = dc=dnson,dc=local
        ldap group suffix = ou=Groups
        ldap user suffix = ou=Users
        ldap machine suffix = ou=Computers
        add user script = /usr/sbin/smbldap-useradd -m "%u"
        delete user script = /usr/sbin/smbldap-userdel "%u"
        add machine script = /usr/sbin/smbldap-useradd -t 0 -w "%u"
        add group script = /usr/sbin/smbldap-groupadd -p "%g"
        add user to group script = /usr/sbin/smbldap-groupmod -m "%u" "%g"
        delete user from group script = /usr/sbin/smbldap-groupmod -x "%u" "%g"
        set primary group script = /usr/sbin/smbldap-usermod -g '%g' '%u'


        # printers configuration        load printers = Yes
 create mask = 0640
        directory mask = 0750
        nt acl support = No
        printing = cups
        printcap name = cups
        deadtime = 10
        guest account = nobody
        map to guest = Bad User
        dont descend = /proc,/dev,/etc,/lib,/lost+found,/initrd
        show add printer wizard = yes
        ; to maintain capital letters in shortcuts in any of the profile folders:^M
        preserve case = yes
        short preserve case = yes
        case sensitive = no                        idmap uid = 10000-20000
        idmap gid = 10000-20000

[netlogon]
        path = /home/netlogon/
        comment = Network Logon Service
        guest ok  = No
        locking  = No
[profiles]        comment = roaming profile share
        path = /home/profiles
        read only = No
        create mask = 0600
        directory mask = 0700
        browseable = No          
        profile acls = yes
        force user = %U
        valid users = %U
        csc policy = disable
[homes]
        comment = Home Directory
        browseable = No
        valid users = %U
        read only = no
        create mask = 1770
        directory mask = 1770

Sau khi lưu file này lại bạn tạo tiếp các thư mục sau nhé.


mkdir /home/netlogonmkdir /home/profiles


Bạn phân quyền lại thư mục  /home/samba/profiles/  như sau.


chmod 1777 /home/profiles/

Bạn khởi động samba và cho samba chạy cùng hệ thống bằng lệnh 


service smb startservice nmb startchkconfig smb onchkconfig nmb on

Đặt mật khẩu cho user quản trị samba ldap.


smbpasswd -w 123456

Sau đó bạn gõ lệnh 
net getlocalsid

để lấy một mã số.nó sẽ bắt bạn nhập mật khẩu.bạn nhập mật khẩu y chang cái mật khẩu bạn lưu trong file  /etc/smbldap-tools/smbldap_bind.conf.Như mình đã nói ở đầu.tốt nhất mật khẩu cứ giống nhau cả loạt đi cho nó nhanh, ít lỗi ,fix mệt.

Bạn coppy cái mã đó và mở file


vim /etc/smbldap-tools/smbldap.conf

Tìm đến dòng


SID ="thêm cái mã đó vô chỗ này."



VD : SID = "S-1-3-32432432432-4-324324324"   (chỉ là ví dụ thôi)

Thứ Tư, 11 tháng 9, 2013

Cấu hình SAMBA + LDAP trên Centos (phần 2)

Cấu hình OPENLDAP.

Bạn gõ lệnh để tạo mật khẩu cho ldap

slappasswd

chú ý : mình lấy mật khẩu là 123456



ở đây mình chọn mật khẩu là 123

Bạn gõ lệnh

vim /etc/openldap/slapd.conf

và và ghi vào với nội dung sau.


include /etc/openldap/schema/core.schemainclude /etc/openldap/schema/cosine.schemainclude /etc/openldap/schema/inetorgperson.schemainclude /etc/openldap/schema/nis.schemainclude         /etc/openldap/schema/samba.schema  đây là dòng thêm vào.gọi file cấu hình mẫu của hệ thống
allow bind_v2
loglevel -1
pidfile /var/run/openldap/slapd.pidargsfile /var/run/openldap/slapd.args



######################################################################## ldbm and/or bdb database definitions#######################################################################
database bdbsuffix "dc=dnson,dc=local"rootdn "cn=Manager,dc=dnson,dc=local"rootpw {SSHA}uUNBHS/G3Gv3M/NY9k0yJplWK4pV32SE dán cái mã ở trên vào chỗ này
directory /var/lib/ldap
index objectClass                       pres,eq#index ou,cn,mail,surname,givenname      eq,pres,subindex cn,sn,uid,displayName    pres,sub,eqindex uidNumber,gidNumber          eqindex uid,memberUid                     eq,pres,subindex nisMapName,nisMapEntry            eq,pres,subindex sambaSID,sambaPrimaryGroupSID,sambaDomainName eq đây là dòng thêm vàoindex default sub đây là dòng thêm vào


Bạn sửa file ldap.conf bằng lệnh

vim /etc/openldap/ldap.conf


BASE dc=dnson,dc=local
URI ldap://10.10.10.1:389
TLS_CACERTDIR /etc/openldap/cacerts


Tiếp sửa file với nội dung sau.bạn gõ lệnh

vim /etc/ldap.conf


base dc=dnson,dc=local

rootbinddn cn=Manager,dc=dnson,dc=local
timelimit 120
bind_timelimit 120
idle_timelimit 3600
nss_base_passwd ou=Users,dc=dnson,dc=local?one
nss_base_passwd ou=Computers,dc=dnson,dc=local?one
nss_base_group ou=Groups,dc=dnson,dc=local?one
nss_base_shadow ou=Users,dc=dnson,dc=local?one
nss_initgroups_ignoreusers root,ldap,named,avahi,haldaemon,dbus,radvd,tomcat, radiusd,news,mailman,nscd,gdm
uri ldap://10.10.10.1:389
ssl no
tls_cacertdir /etc/openldap/cacerts
pam_password crypt


Tiếp theo bạn sửa file /etc/nsswitch.conf . đây là file quy định chuyển đổi lưu trữ.ta chuyển từ lưu trữ tên và mật khẩu user qua cho ldap quản lý.

vim /etc/nsswitch.conf

33 passwd : files ldap
34 shadow: files ldap
35 group: files ldap

Coppy file database mẫu của hệ thống bằng các lệnh sau.

cp /usr/share/doc/samba-3.0.33/LDAP/samba.schema /etc/openldap/schema/
cp /etc/openldap/DB_CONFIG.example /var/lib/ldap/DB_CONFIG

Cấu hình LDAP client.

Bạn gõ lệnh

setup

Chọn Authentication configuration -> Run Tool (cứ làm như hình dưới là ok hết.)




đoạn này chỉnh lại thành ldap://10.10.10.1/


Bạn mở file

vim /etc/pam.d/system-auth

 vào thêm vào cuối dòng của file đó câu.

session optional pam_mkhomedir.so skel=/etc/skel umask=077

Bật ldap và cho ldap chạy cùng hệ thống.


service ldap start
service nscd start
chkconfig ldap on
chkconfig nscd on