顯示具有 howto 標籤的文章。 顯示所有文章
顯示具有 howto 標籤的文章。 顯示所有文章

2009年8月30日 星期日

如何設定 ldap 登入服務 – OpenLDAP Linux authentication howto

OpenLDAP 登入服務器

上文提到如何安裝 OpenLDAP 服務器, 今次將會提到如何在 ubuntu上把 OpenLDAP 服務器設定成一個登入服務器. 這樣你就可以使用同一組資料登入多個不同的服務器.

先作服務器端設定

安裝轉換工具 migration tools
sudo apt-get install migrationtools
更改 migration_common.ph 設定檔, 位置在 /usr/share/perl5
sudo vi /usr/share/perl5/migration_common.ph
根據服務器端的設計更改以下兩行
# Default DNS domain
$DEFAULT_MAIL_DOMAIN = “example.com”;
# Default base
$DEFAULT_BASE = “dc=example,dc=com”;
開始轉移登入資料 (/tmp 改成你的理想位置)
export ETC_SHADOW=/etc/shadow #把shadow 跟passwd 一同載入
./migrate_base.pl > /tmp/base.ldif
./migrate_group.pl /etc/group /tmp/group.ldif
./migrate_hosts.pl /etc/hosts /tmp/hosts.ldif
./migrate_passwd.pl /etc/passwd /tmp/passwd.ldif
用以下命令分別載入到 ldap 服務器
ldapadd -D “cn=admin,dc=domain,dc=com” -W -f /tmp/base.ldif
ldapadd -D “cn=admin,dc=domain,dc=com” -W -f /tmp/group.ldif
ldapadd -D “cn=admin,dc=domain,dc=com” -W -f /tmp/passwd.ldif
ldapadd -D “cn=admin,dc=domain,dc=com” -W -f /tmp/hosts.ldif
apt-get install 安裝認證需要的元件
Modules require for authentication
libnss-ldap – NSS module for using LDAP as a naming service
libpam-ldap – Pluggable Authentication Module allowing LDAP interfaces
libnss-ldapd – NSS module for using LDAP as a naming service
perdition-ldap – Library to allow perdition to access LDAP based popmaps
libpam-cracklib
pam library做小許 bug fix
ln -s pam_unix.so pam_pwdb.so
這樣, 服務器端的設定就完成了

再做客戶端的設定

Vi /etc/ldap.conf
host ldap.example.com
uri ldap://<服務器ip位置>:389/
base ou=People,dc=example,dc=com
nss_initgroups_ignoreusers backup,bin,daemon,dhcp,games,gnats,irc,klog,libuuid,list,lp,mail,man,munin,mysql,news,openldap,proxy,root,sshd,sync,sys,syslog,uucp,www-data
vi /etc/nsswitch.conf # 登入方法設定
passwd: ldap compat
shadow: ldap compat
group: ldap compat
vi /etc/pam.d/common-account #設定 account 認證方法
account sufficient pam_ldap.so
account required pam_unix.so try_first_pass
vi /etc/pam.d/common-auth # 設定登入認證方法
auth sufficient pam_ldap.so
auth requisite pam_unix.so nullok_secure try_first_pass
auth optional pam_smbpass.so migrate missingok
vi /etc/pam.d/common-password #設定密碼管理
password sufficient pam_ldap.so
password required pam_unix.so nullok obscure min=4 max=8 md5 try_first_pass
password optional pam_smbpass.so nullok use_authtok use_first_pass missingok

測試設定

getent passwd | grep
會發現參數出現兩次
這樣客戶端就能使用中央使用者管理

2009年8月18日 星期二

vpn solution2 – windows openvpn client 免費的vpn 客戶端

上文提及過 openvpn server的制作方法, 這篇文章會介紹服務器端與客戶端配合的一個例子.

在客戶端方面, 用家大部份都會用 Windows + openvpn. 在 Windows 下安裝 openvpn 十分簡單, 只需要以下步驟

  1. 到這裡下載 openvpn 圖形介面客戶端
    http://openvpn.se/files/install_packages/openvpn-2.0.9-gui-1.0.3-install.exe
  2. 雙click install.exe 安裝
  3. 到 C:\Program Files\OpenVPN\config 創建 / 編輯 ovpn 檔案 (yourservername.ovpn)
  4. .opvn示範檔案如下
    1. client
    2. dev tap
    3. proto udp

    4. # change this to your server’s address
    5. remote 123.123..123..123 1194
    6. resolv-retry infinite
    7. nobind
    8. persist-key
    9. persist-tun

    10. #tls-client
    11. ca keys/ca.crt
    12. cert keys/keithyau.crt
    13. key keys/keithyau.key

    14. #ensure that we are talking to a server
    15. ns-cert-type server

    16. #confirm we are talking to the correct server
    17. #tls-auth ta.key 1
    18. # Select a cryptographic cipher.
    19. # If the cipher option is used on the server
    20. # then you must also specify it her e.
    21. cipher AES-128-CBC

    22. # Enable compression on the VPN link.
    23. comp-lzo

    24. #fragment 1400
    25. # enable user/pass authentication
    26. # auth-user-pass

  5. 把鑰匙拷貝到 C:\Program Files\OpenVPN\config\keys , 以下是在服務器端上鑰匙的制法 (把keithyau 換成你的使用者名字, 詳情參考 http://keithyau.wordpress.com/2009/02/07/vpn-solution-2-openvpn/)
    1. sudo su
      cd /etc/openvpn/examples/easy-rsa/2.0/
      source ./vars
      ./clean-all
      ./build-ca
      ./build-key-server server
      ./build-key keithyau
      ./build-dh
      cd keys
      openssl dhparam -out dh1024.pem 1024
      cd ..
      openvpn –genkey –secret ta.key #optional
  6. 在右下角 openvpn icon按連接
  1. 測試連線

令服務器能接受以上設定的請求, 相應需要以下的設定

    # Which local IP address should OpenVPN
    # listen on? (optional)
    local 192.168.1.102
    port 1194
    proto udp
    dev tap0
    #direct these to your generated files
    ca /etc/openvpn/examples/easy-rsa/2.0/keys/ca.crt
    cert /etc/openvpn/examples/easy-rsa/2.0/keys/server.crt
    key /etc/openvpn/examples/easy-rsa/2.0/keys/server.key
    dh /etc/openvpn/examples/easy-rsa/2.0/keys/dh1024.pem
    ifconfig-pool-persist ipp.txt
    #需要 dhcp 服務器 的配合
    server 10.3.0.0 255.255.255.0
    # 服務器上沒有 dhcp 服務器的請選這行
    # server-bridge 192.168.1.102 255.255.255.0 192.168.1.230 192.168.1.231
    keepalive 10 120
    #encryption
    cipher AES-128-CBC
    #Push routing configuration
    #push “route 192.168.2.0 255.255.255.0″
    #tls-auth ta.key 0
    comp-lzo
    #fragment 1400
    #limit the number of connections
    max-clients 5
    #some secuurity settings
    # do not use if running server on Windows
    user nobody
    group nogroup
    persist-key
    persist-tun
    #log file settings
    status openvpn-status.log
    verb 3
    # authentication plugin
    #forces client to have a linux acount in order to connect (Not for Windows user)
    # plugin /usr/lib/openvpn/openvpn-auth-pam.so login

這裡有安裝 DHCP server 的方法

sudo apt-get install dhcp3-server
sudo vi /etc/default/dhcp3-server
更改 為 INTERFACES=”br0″ # br0 = 你的網卡名稱

sudo vi /etc/dhcp3/dhcpd.conf

把其中一個示範修改為 (10.3.0.0 是你打算指派的網絡)
subnet 10.3.0.0 netmask 255.255.255.0 {
range 10.3.0.100 10.3.0.200;
option routers 192.168.1.1;
}

/etc/init.d/dhcpd restart
/etc/init.d/openvpn restart

這樣你的 Openvpn 就能成功在 linux → windows 間建立起來了