一、服務端配置
1、修改openvpn的主配置檔案,添加如下内容
[root@ttt openvpn]# cat /etc/openvpn/server.conf |more #########auth password######## script-security 3 ###--加入腳本處理,如用密碼驗證 auth-user-pass-verify /etc/openvpn/checkpsw.sh via-env ###指定隻用的認證腳本 client-cert-not-required #####不請求客戶的CA憑證,使用User/Pass驗證,如果 同時啟用證書和密碼認證,注釋掉該行 username-as-common-name ### 使用客戶提供的UserName作為Common Name ############################ |
2、按照配置檔案中的腳本路徑放置checkpsw.sh
[root@ttt openvpn]# cat checkpsw.sh #!/bin/sh ########################################################### # checkpsw.sh (C) 2004 Mathias Sundman <[email protected]> # # This script will authenticate Open××× users against # a plain text file. The passfile should simply contain # one row per user with the username first followed by # one or more space(s) or tab(s) and then the password. PASSFILE="/etc/openvpn/psw-file" LOG_FILE="/var/log/openvpn-password.log" TIME_STAMP=`date "+%Y-%m-%d %T"` if [ ! -r "${PASSFILE}" ]; then echo "${TIME_STAMP}: Could not open password file \"${PASSFILE}\" for reading." >> ${LOG_FILE} exit 1 fi CORRECT_PASSWORD=`awk '!/^;/&&!/^#/&&$1=="'${username}'"{print $2;exit}' ${PASSFILE}` if [ "${CORRECT_PASSWORD}" = "" ]; then echo "${TIME_STAMP}: User does not exist: username=\"${username}\", password=\"${password}\"." >> ${LOG_FILE} if [ "${password}" = "${CORRECT_PASSWORD}" ]; then echo "${TIME_STAMP}: Successful authentication: username=\"${username}\"." >> ${LOG_FILE} exit 0 echo "${TIME_STAMP}: Incorrect password: username=\"${username}\", password=\"${password}\"." >> ${LOG_FILE} exit 1 |
3、賦予該腳本執行權限
chmod +x checkpsw.sh |
4、準備使用者名和密碼認證檔案,使用者名和密碼用空格隔開,同時確定openvpn啟動使用者可讀取該檔案
[root@ttt openvpn]# cat psw-file client01 123456 client02 123456789 為了安全起見,将psw-file的權限盡量改小 [root@ttt openvpn]# chmod 400 psw-file |
5、重新開機openvpn的服務程序
二、修改用戶端的配置檔案,添加下面一行
auth-user-pass |
三、開啟windows用戶端,進行密碼認證