OpenVPN 设置账号密码登录
前面我们介绍了openvpn使用秘钥的方式登录,每次创建新用户的时候需要创建一个证书,并且需要将证书在发给使用的人员。个人觉得比较麻烦,特意查阅了一下openvpn配置账户密码登录的方式。
OpenVPN 设置账号密码登录
Linux
前面我们是使用openvpn 秘钥的方式登录,这种登录安全性比较高。但是运维操作起来比较麻烦,如果有ldap的也推荐使用ldap集成openvpn。但是这里我们偷个懒,通过设置账号密码的方式连接vpn
<img src="https://img.mryunwei.com/uploads/2023/05/20230504015441404.png" alt>
<img src="https://img.mryunwei.com/uploads/2023/05/20230504015441404.png" alt>
<h2>CentOS 7 搭建OpenVPN服务器</h2>
<img src="https://img.mryunwei.com/uploads/2023/05/20230504095444193.gif">新闻联播老司机
<li>
20年2月4日</li>
<li>
喜欢:1
</li>
<li>
浏览:35.4k
</li>
配置OpenVPN
首先我们需要编写一个用户认证的脚本 (脚本是由openvpn官网提供的)
vim /etc/openvpn/checkpsw.sh #!/bin/sh ########################################################### 1. checkpsw.sh (C) 2004 Mathias Sundman 1. 1. This script will authenticate OpenVPN users against 1. a plain text file. The passfile should simply contain 1. one row per user with the username first followed by 1. 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 755 /etc/openvpn/checkpsw.sh
现在我们配置用户密码文件
cat /etc/openvpn/psw-file abcdocker 123456 abc 123456 test test #前面为用户名,后面为密码。 中间使用空格分开
接下来我们需要openvpn的server.conf
cat >>/etc/openvpn/server.conf<接下来我们需要修改client.ovpn
client dev tun proto tcp remote 192.168.0.11 1194 resolv-retry infinite nobind persist-key persist-tun ca ca.crt ;cert cyh.crt #注释 ;key cyh.key #注释 tls-auth ta.key 1 cipher AES-256-CBC comp-lzo verb 3 auth-user-pass #使用用户名密码登录openvpn服务器 #主要是注释crt和key路径,以及添加一行auth-user-pass接下来我们重启一下openvpn即可
[root@vpn ~]# ps -ef|grep openvpn root 54047 53844 0 14:38 pts/0 00:00:00 grep --color=auto openvpn [root@vpn ~]# /usr/local/openvpn/sbin/openvpn --daemon --config /etc/openvpn/server.conf然后我们导出client.ovpn,从新启动客户端就可以了
![]()
![]()
本文转自:http://www.89cool.com/811.html
相关文章:
- Kubernetes 1.14 二进制集群安装
- Shell 变量及函数讲解 [2]
- Kubenetes 1.13.5 集群二进制安装
- Kuerbernetes 1.11 集群二进制安装