前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >基于用户名和密码方式登录OpenV**

基于用户名和密码方式登录OpenV**

作者头像
陳斯托洛夫斯記
发布2022-10-04 14:28:29
2.9K0
发布2022-10-04 14:28:29
举报
文章被收录于专栏:XBD

安装openv*

编写一个用户认证脚本 vim /etc/openvpn/checkpsw.sh

代码语言:javascript
复制
#!/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

配置用户名密码文件

代码语言:javascript
复制
vim /etc/openvpn/psw-file 

test1 123456
test2 123456

格式:用户名 密码

修改 server.conf 文件

代码语言:javascript
复制
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** 文件

代码语言:javascript
复制
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**服务

验证

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档