上篇文章写了基于证书的认证方式,这里记录下基于用户密码的认证方式
在Centos7 搭建Openvpn环境基础上修改
修改服务端 server.conf配置文件
添加几个参数
#客户端不进行证书认证,如果不加将实现证书和用户密码双重认证
client-cert-not-required
#用户和密码验证脚本
auth-user-pass-verify /etc/openvpn/checkpsw.sh via-env
#使用用户名密码登录认证
username-as-common-name
#脚本安全级别
script-security 3
创建脚本和用户密码文件
vim /etc/openvpn/checkpsw.sh
#!/bin/bash
###########################################################
# 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
#增加执行权限 (2020-12-17标注:不加权限,连接会用户密码认证失败,因为执行不了脚本)
chmod +x /etc/openvpn/checkpsw.sh
#用户密码文件,格式:一行对应一个用户
vim /etc/openvpn/psw-file
jinc 123456
test 456789
#修改权限
chmod 777 /etc/openvpn/psw-file
chown root.openvpn /etc/openvpn/* -R
#重启openvpn服务
systemctl restart openvpn@server
win10 客户端配置文件修改
#注释掉
;cert client.crt
;key client.key
#添加上
auth-user-pass
相关文章
OpenVPN win10客户端连接几个警告信息解决
Centos7 搭建OpenVPN 基于证书认证
L2TP+IPsec vpn搭建
Centos7搭建PPTP VPN服务
本文最后更新时间 2023-06-07
文章链接地址:https://me.jinchuang.org/archives/570.html
本文内容未来会持续更新·本站文章除注明[转载|引用|原文]出处外,均为本站原生内容,转载前请注明出处
你好 我在电脑1用阿里云搭建了openvpn是可以用账号密码登录的 ,但是把配置config文件夹发给另外一台电脑去登录,那个账号密码输入后 还会再次弹出来
求指导
我这里使用密码认证是在我之前的文章证书连接方式ok的基础上做修改,还有就是脚本中路径、系统环境都和你的不一定相同,注意下这点还有多看服务端连接日志报错信息。
请问这个可以设置每个连接账号的使用时间吗,还有所有客户端都用一个client.ovpn,不会给卡下线吧?
时间限制这个我也不清楚,所有客户端共用client.ovpn可以的,不会卡下线,看你连多少个了
前辈你好,我脚本安全级别已经设置为3了还是提示无法执行外部程序有空看到的话能给指导下嘛
请问解决了吗,我也碰到类似的问题,已经加了脚本安全级别3了,就是执行不了,日志报错WARNING: Failed running command (--auth-user-pass-verify): could not execute external program
我测试了下,如果把脚本去掉执行权限就会报此错误,客户端提示:错误的凭据,请重试...
所以要给予脚本对应的执行权限,chmod +x checkpsw.sh
是不是有可能权限问题无法执行呢?