#!/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
然后你还需要创建一个密码本文件 vim /etc/openvpn/psw-file,每一行一个用户,用户名和密码之间用空格隔开:
1 2 3
user1 pass1 user2 pass2 user3 pass3
至此服务端配置完成。
配置内核和防火墙,启动服务端
第一步,开启路由转发功能
1 2 3
sed -i '/net.ipv4.ip_forward/s/0/1/' /etc/sysctl.conf sed -i '/net.ipv4.ip_forward/s/#//' /etc/sysctl.conf sysctl -p
Sat Apr 20 14:30:34 2019 /sbin/ip linkset dev tun0 up mtu 1500 Sat Apr 20 14:30:34 2019 /sbin/ip addr add dev tun0 local 10.8.0.6 peer 10.8.0.5 Sat Apr 20 14:30:34 2019 /sbin/ip route add 192.168.0.0/24 via 10.8.0.5 Sat Apr 20 14:30:34 2019 /sbin/ip route add 10.8.0.1/32 via 10.8.0.5 Sat Apr 20 14:30:34 2019 Initialization Sequence Completed