编写一个用户认证脚本 vim /etc/openvpn/checkpsw.sh
#!/bin/sh
###########################################################
# checkpsw.sh (C) 2004 Mathias Sundman
#
# This script will authenticate OpenVPN 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="/etc/openvpn/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}
exit 1
fi
if [ "${password}" = "${CORRECT_PASSWORD}" ]; then
echo "${TIME_STAMP}: Successful authentication: username=\"${username}\"." >> ${LOG_FILE}
exit 0
fi
echo "${TIME_STAMP}: Incorrect password: username=\"${username}\", password=\"${password}\"." >> ${LOG_FILE}
exit 1
chmod +x /etc/openvpn/checkpsw.sh
配置用户名密码文件
vim /etc/openvpn/psw-file
test1 123456
test2 123456
格式:用户名 密码
修改 server.conf 文件
vim /etc/openvpn/server.conf # 在最后一行追加以下内容
script-security 3
auth-user-pass-verify /etc/openvpn/checkpsw.sh via-env
username-as-common-name
verify-client-cert none
修改chen.ov** 文件
vim chen.ovpn
client
dev tun
proto udp
remote 139.198.15.121 1194
resolv-retry infinite
nobind
persist-key
persist-tun
ca ca.crt
;cert chen.crt # 注释此行
;key chen.key # 注释此行
tls-auth ta.key 1
cipher AES-256-CBC
comp-lzo
verb 3
auth-user-pass # 添加此行
重启openv**服务
验证