大綱
一、前言
二、概述
三、具體配置過程
四、總結
注,實戰環境 CentOS 5.5 x86_64,軟件版本 Open*** 2.1,軟件下載:http://yunpan.cn/QzT8fGsX8S75a 訪問密碼 e8e4。
一、前言
在上一篇博客中我們提出一個問題,下面我們來回顧一下:
前面做的實驗都是由服務端先生成客戶端證書,然後分發到客戶端上,讓客戶端通過證書連接到服務器上。但有時候,這樣的分發是比較麻煩的(也不安全)。這樣,我們可以考慮另外一種方式: 只在服務端製作客戶端證書,而客戶端只需要有ca.crt文件,而不需要拿到客戶端證書,當登陸服務器的時候是通過用戶名和密碼即可登錄Open***服務器。在這一篇博客中我們和大家解決這個問題,嘿嘿!
二、概述
在這裏簡單的和大家先說一下實驗步驟:
1.安裝相關軟件包
mysql服務器
PAM組件(pam_mysql)
sasl
2.創建Open***使用的數據庫與表
3.創建測試用戶
4.配置PAM mysql認證模塊
5.測試pam_mysql是否工作正常
6.配置Open***服務器及客戶端配置文件
7.測試連接
注,本文的配置過程緊接着上一篇博文,不清楚的博友可以先看上一篇博文。
三、具體配置過程
1.安裝相關軟件包
mysql服務器
PAM組件(pam_mysql)
sasl
[root@gateway ~]# yum install -y mysql mysql-devel [root@gateway ~]# yum install -y pam_krb5 pam_mysql pam pam-devel [root@gateway ~]# yum install -y cyrus-sasl cyrus-sasl-plain cyrus-sasl-devel cyrus-sasl-lib cyrus-sasl-gssapi
2.創建Open***使用的數據庫與表
[root@gateway ~]# mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 65 Server version: 5.0.37-log Source distribution Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> create database ***; mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | test | | *** | +--------------------+ 4 rows in set (0.02 sec) mysql> use ***; mysql> CREATE TABLE ***user ( name char(20) NOT NULL, password char(128) default NULL, active int(10) NOT NULL DEFAULT 1, PRIMARY KEY (name) ); mysql> show tables; +---------------+ | Tables_in_*** | +---------------+ | ***user | +---------------+ 1 row in set (0.00 sec)
3.創建測試用戶
[root@gateway ~]# mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 65 Server version: 5.0.37-log Source distribution Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> insert into ***user (name,password) values('user1',password('123456')); mysql> insert into ***user (name,password) values('user2',password('123456')); mysql> insert into ***user (name,password) values('user3',password('123456')); mysql> select * from ***user; +-------+-------------------------------------------+--------+ | name | password | active | +-------+-------------------------------------------+--------+ | user1 | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | 1 | | user2 | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | 1 | | user3 | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | 1 | +-------+-------------------------------------------+--------+ 3 rows in set (0.00 sec) 注,我這裏創建三個測試用戶。
4.配置PAM mysql認證模塊
[root@gateway ~]# vim /etc/pam.d/open*** auth required pam_mysql.so user=*** passwd=***123 host=127.0.0.1 db=*** \ table=***user usercolumn=name passwdcolumn=password \ where=active=1 sqllog=0 crypt=2 account required pam_mysql.so user=*** passwd=***123 host=127.0.0.1 db=*** \ table=***user usercolumn=name passwdcolumn=password \ where=active=1 sqllog=0 crypt=2 #crypt(0) -- Used to decide to use MySQL's PASSWORD() function or crypt() #0 = No encryption. Passwords in database in plaintext. NOT recommended! #1 = Use crypt #2 = Use MySQL PASSWORD() function
5.測試pam_mysql是否工作正常
[root@gateway ~]# /etc/init.d/saslauthd start 啓動 saslauthd: [確定] [root@gateway ~]# chkconfig saslauthd on [root@gateway ~]# chkconfig saslauthd --list saslauthd 0:關閉 1:關閉 2:啓用 3:啓用 4:啓用 5:啓用 6:關閉 [root@gateway ~]# testsaslauthd -u user1 -p 123456 -s open*** 0: OK "Success."
注,如果出現: 0: OK “Success.”, 表示測試成功。如果出現錯誤可以從系統日誌及安全日誌裏看到出錯信息,系統日誌: /var/log/messages與安全日誌: /var/log/secure。
6.配置Open***服務器及客戶端配置文件
1).增加open***認證模塊
[root@gateway open***]# cd /etc/open***/ [root@gateway open***]# ls | grep open***-auth-pam open***-auth-pam.so
注,這個認證模塊我已經上傳到雲盤了,需要的朋友自行下載。
2).修改server.conf配置文件
[root@gateway open***]# vim server.conf port 1194 proto udp dev tap ca ca.crt cert server.crt key server.key dh dh1024.pem server 10.8.0.0 255.255.255.0 push "route 192.168.189.0 255.255.255.0" ;client-to-client keepalive 10 120 comp-lzo persist-key persist-tun status open***-status.log verb 3 push "dhcp-option DNS 10.8.0.1" push "dhcp-option DNS 8.8.8.8" push "dhcp-option DNS 8.8.4.4" plugin ./open***-auth-pam.so open*** #申明open***使用的插件, open***爲插件參數,和pam_mysql的service name是一樣的 client-cert-not-required #不請求客戶的CA證書, 使用用戶名/密碼驗證 (本配置中沒指定, 使用雙重認證, 證書和密碼驗證) log open***.log
3).修改客戶端配置文件
client dev tap proto udp remote *.*.*.* 1194 #公網IP resolv-retry infinite nobind persist-key persist-tun ca 146\\ca.crt cert 146\\client1.crt key 146\\client1.key ns-cert-type server comp-lzo verb 3 auth-user-pass #在客戶端配置文件中加入中加入這一行,重新啓動客戶端連接到*** server時就需要輸入用戶名和密碼了。
注,下面我們來連接測試一下!
7.測試連接
好了,到這裏我們的配置就全部完成了,嘿嘿!
四、總結
1.問題說明(有關open***的PAM認證插件)
Open*** 2.1以上的Open***的open***-auth-pam.so都會出現驗證錯誤的問題,這裏需要我們重新編譯一個低版本的,我這裏用2.0.7的,大家也可以使用2.0.9版本的。大家可以在雲盤中自行下載。
2.在配置Open***的同時大家得注意配置iptables防火牆,有時候連接不上Open***大多數是因爲防火牆的問題。
好了,今天的博客就到這裏了,最後希望大家有所收穫^_^……