大用户量下Open***部署方案(二)

本文介绍如何通过脚本批量生成用户名密码,并自动配置客户端文件,实现OpenVPN的大规模部署及用户验证流程。

   采用用户名密码认证的话,在客户端只需要ca.crt文件即可。这样只是客户端验证了服务端的合法性,而缺少了服务器对客户端合法性的验证,安全性有所降低。

1、用户名密码验证:

  在上一篇的基础上,服务端配置文件里添加下列内容可实现基于checkpsw.sh脚本验证用户名密码的方式。

   #use username & passwd to login
   script-security 3 system
   auth-user-pass-verify /etc/open***/checkpsw.sh via-env
   client-cert-not-required                                #不需要客户端证书
   username-as-common-name


下面是checkpsw.sh脚本的内容:

#!/bin/sh
###########################################################
# checkpsw.sh (C) 2004 Mathias Sundman <mathias@open***.se>
# This script will authenticate Open*** 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/open***/psw-file"
LOG_FILE="/etc/open***/open***-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、创建create-user脚本用来在/etc/open***/psw-file文件里批量添加用户名密码,格式如下

client1 pass1

脚本内容:

#!/bin/sh
for ((i=1;$i<65;i++))
do
echo "client$i pass$i">>/etc/open***/psw-file     #将用户名密码信息输出到psw-file文件
done

注:我们在上一篇的server.conf里定义了“server 10.8.0.0 255.255.0.0”,即客户端的可用IP从10.8.1.0-10.8.254.254。又因为win下虚拟网卡必须采用/30段的IP。30段的子网段划分如下:0-3,4-7,8-11 ... 252-255,共分为64段,除去网络号和网关每段能用的IP地址为1、2;5、6;9、10...253、254.所以10.8.1.0、10.8.2.0、...10.8.254.0每一段都只能给64个客户端用,所以,次open***服务器共可支持给254*64个客户端分配IP。

3、指定客户端ip

在server.conf里注释掉以下两行

;client-config-dir /etc/open***/ccd
;route 10.8.0.0 255.255.255.252,

在ccd里创建以用户名为名的文件,例如client1,添加如下内容

ifconfig-push 10.8.0.5 10.8.0.6

这里:大量客户端配置文件就需要一批量方式生成配置文件并添加内容。创建ccd-client脚本,内容如下:

#!/bin/bash
IP_PRE=10.8.0.
FILE_PRE=client
for i in {1..64}
do
file_name=$FILE_PRE$i
ip_end1=$(($i*4-3))
ip_end2=$(($i*4-3+1))
ip1=$IP_PRE$ip_end1
ip2=$IP_PRE$ip_end2
echo "ifconfig-push $ip1 $ip2" > $file_name
done

IP_PRE1=10.8.1.
for i in {1..64}
do
file_name=$FILE_PRE$(($i+64))
ip_end1=$(($i*4-3))
ip_end2=$(($i*4-3+1))
ip1=$IP_PRE1$ip_end1
ip2=$IP_PRE1$ip_end2
echo "ifconfig-push $ip1 $ip2" > $file_name
done


此脚本生成的客户端控制文件内容如下图

wKiom1MwO67y0NtGAABXj4Tslek356.jpg

有了这三个脚本,就可以完成批量生成用户名密码、批量在ccd目录里添加客户配置文件、以及对用户名和密码的验证过程。

这次部署中:参考了几篇文章,启发不小,链接如下

http://www.360doc.com/content/11/1123/22/4171006_166878811.shtml
http://blog.chinaunix.net/uid-24250828-id-3536671.html
http://hi.baidu.com/opwrt/item/9e0373d6115ac42838f6f761


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值