一键安装openvpn并配置使用账号密码登陆

警告
本文最后更新于 2020-06-15 15:18,文中内容可能已过时。

脚本github地址:https://github.com/Nyr/openvpn-install

下载脚本:

1
wget https://raw.githubusercontent.com/Nyr/openvpn-install/master/openvpn-install.sh

安装:

1
sh openvpn-install.sh

没有特殊需求默认即可

56995-n3gc40qsaf.png
56995-n3gc40qsaf.png

soul用户的客户端配置文件路径:/root/soul.ovpn

将此文件导入到openvpn中,连接即可。

配置使用账号密码验证

1.创建脚本:vim /etc/openvpn/checkpsw.sh

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/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="/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

2.添加权限

1
chmod 755 /etc/openvpn/checkpsw.sh

3.添加账号密码

1
echo 'username1 password1' >> /etc/openvpn/psw-file

4.修改server.conf

1
2
3
4
5
# 追加以下内容
script-security 3
auth-user-pass-verify /etc/openvpn/checkpsw.sh via-env
username-as-common-name
verify-client-cert none

5.重启服务

1
systemctl restart openvpn-server@server

6.修改客户端文件soul.ovpn

1
2
# 追加以下内容,<cert>和<key>部分可以删掉
auth-user-pass

客户端填写用户名密码

20302-ekztnpyyhjj.png
20302-ekztnpyyhjj.png

请我喝杯水
SoulChild 微信号 微信号
SoulChild 微信打赏 微信打赏
0%