采用用户名密码认证的话,在客户端只需要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 |
此脚本生成的客户端控制文件内容如下图
有了这三个脚本,就可以完成批量生成用户名密码、批量在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