频道栏目
首页 > 资讯 > 其他 > 正文

OPENVPN开启用户密码认证

14-08-09        来源:[db:作者]  
收藏   我要投稿

一、服务端配置

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 <mathias@openvpn.se>
#
# 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="/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}
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

3、赋予该脚本执行权限

[root@ttt openvpn]# 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

[root@ttt openvpn]# chown nobody.nobody psw-file

5、重启openvpn的服务进程

二、修改客户端的配置文件,添加下面一行

auth-user-pass

三、开启windows客户端,进行密码认证


相关TAG标签
上一篇:故障诊断复习
下一篇:tornado+ansible+twisted+mongodb运维自动化系统开发(四)
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站