`
sbfwfn
  • 浏览: 16487 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

openvpn建立1 转过来的

阅读更多
OPENVPN  笔记
openvpn的使用场景很多,不同的使用场景,设置也有很大的不同,client to host 这应该是一种最简单的方式,对于个人用户来说,这应该是应用最多。
下面的图是从google找到的,文章地址。如果我们的服务器端,是放在公司的总部,需要和公司内网进行链接,那么就可以参考这个图来进行设置。

OPENVPN验证方式
采用证书的方式,我们就需要创建CA,颁发客户端和服务器端的证书。
采用户名和密码的方式,那么用户和密码可以保存在数据库或者ldap上。
当然我们是可以把openvpn,配置成采用同时支持两种方式验证。也就是说服务器端支持两种方式的验证,采用哪种方式验证,由客户端设置来决定。
证书方式
只使用证书
证书+密码

USER/PASSWORD
mysql
ldap

一:实验环境
在国外有一台xen的vps,装了centos5.3的系统,现在希望在服务器上安装openvpn,远程的客户端,可以通过连接vpn,直接访问国外的网站。
客户端一般都是在内网。假设内网的网段上192.168.1.0/24
vpn server
hostname mail.18demo.com
ip:66.160.197.199

由于我需要测试pop验证和ldap验证,所以我就安装iredmail的ldap版本(iredmail的脚本)。这样就可以测试pop验证和ldap验证。

二:初始化设置
由于我的xen的vps,极度精简,下面安装的软件和设置,有些是个人偏好。

iptables是必须安装的。
客户端和vpn server时间最好同步
lrzsz 是用来ssh客户端可以直接上传,下载文件 ssh客户端设置

采用yum的方式安装openvpn,所以需要添加rpmforge,注意你的机器是32 还是64, 需要注意的是rpmforge 提供的是2.09版本,EPEL提供的是2.1版本,2.1的版本修复了一个注销证书的bug。别的没有发现有什么太大的不同。
#修改hostname
sed -i "s/HOSTNAME=eddie1/HOSTNAME=mail.18demo.com/" /etc/sysconfig/network
echo "127.0.0.1   mail.18demo.com mail localhost localhost.localdomain" > /etc/hosts
hostname mail.18demo.com

#安装必备软件
yum -y install wget gzip bzip2 lrzsz vixie-cron vim-enhanced tmpwatch unzip ntp mlocate zip ntp iptables mlocate

#设置vim
mv /bin/vi /bin/vi.save
ln -s /usr/bin/vim /bin/vi
cp /etc/vimrc /etc/vimrc.save
sed -i "39 s/^/ set number \n filetype on\n set history=1000\n syntax on\n set tabstop=4\n set showmatch\n set vb t_vb=\n set mouse=a\n set ignorecase\n set autowrite\n /" /etc/vimrc


#同步时间和时区
mv /etc/localtime /etc/localtime.save
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
ntpdate cn.pool.ntp.org

#设置acl
sed -i "s/errors=remount-ro/acl,errors=remount-ro /" /etc/fstab
mount -o remount,rw,acl /

二:安装iredmail ldap
安装iredmail,可以测试pop验证和ldap验证。
三:OPENVPN
安装openvpn
rpmforge 提供的是2.09的版本,EPEL提供的是2.1的版本,我使用2.1的版本,2.1 修复注销证书的bug。另外EPEL的源里才有ldap验证的插件。

rpmforge
rpm -Uhv http://apt.sw.be/redhat/el5/en/i386/rpmforge/RPMS/rpmforge-release-0.3.6-1.el5.rf.i386.rpm # <-- For i386
rpm -Uhv http://apt.sw.be/redhat/el5/en/x86_64/rpmforge/RPMS//rpmforge-release-0.3.6-1.el5.rf.x86_64.rpm # <-- For x86_64
EPEL yum

#EPEL yum

rpm -Uhv http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-3.noarch.rpm # <-- For i386
rpm -Uhv http://download.fedora.redhat.com/pub/epel/5/x86_64/epel-release-5-3.noarch.rpm # <-- For x86_64

安装openvpn
yum -y install openvpn
查看openvpn的安装位置

updatedb
locate openvpn
复制模板
将模版中的easy-rsa的目录复制到/etc/openvpn/的路径下,这些都是创建证书的脚本。这些脚本有两个版本。2.0的目录是最新版本,建议大家使用这个。目录下有readme,大家可以看看。
注意,不同版本openvpn的easy-rsa的路径不太一样,通过上面locate命令,找出路径,下面是2.1版本的openvpn的路径。

cp -R /usr/share/doc/openvpn-2.0.9/easy-rsa/ /etc/openvpn/
cp -R /usr/share/openvpn/easy-rsa /etc/openvpn/
cd /etc/openvpn/easy-rsa/2.0/

编辑 vars脚本,
根据自己的情况来填写,其实这些内容,你不修改,也不会影响你使用。
vi vars
export KEY_COUNTRY="CN"
export KEY_PROVINCE="BJ"
export KEY_CITY="BeiJing"
export KEY_ORG="iredmail"
export KEY_EMAIL="shake.chen@gmail.com"

让脚本可运行
目录下的所有脚本目前都是不可运行,需要让脚本有可执行的权限

chmod +rwx *
将vars载入系统环境之中
source ./vars

执行clean-all脚本,
留意,这个时候,就会在目录下产生keys的文件夹。
./clean-all
# ll keys/
total 4
-rw-r--r-- 1 root root 0 Jul 26 02:16 index.txt
-rw-r--r-- 1 root root 3 Jul 26 02:16 serial

建立CA证书,
使用pkitool 命令,可以减少交互过程。产生 ca.crt 和 ca.key
./pkitool --initca
# ll keys/
total 12
-rw-r--r-- 1 root root 1212 Jul 26 02:17 ca.crt
-rw------- 1 root root  887 Jul 26 02:17 ca.key
-rw-r--r-- 1 root root    0 Jul 26 02:16 index.txt
-rw-r--r-- 1 root root    3 Jul 26 02:16 serial

建立DH参数文件
会产生dh1024.pem文件
./build-dh
ll keys/
total 16
-rw-r--r-- 1 root root 1212 Jul 26 02:17 ca.crt
-rw------- 1 root root  887 Jul 26 02:17 ca.key
-rw-r--r-- 1 root root  245 Jul 26 02:18 dh1024.pem
-rw-r--r-- 1 root root    0 Jul 26 02:16 index.txt
-rw-r--r-- 1 root root    3 Jul 26 02:16 serial

防止恶意攻击(可选)
如DOS、UDP port flooding,生成一个"HMAC firewall", 这个功能可以不启用,减少麻烦。
openvpn --genkey --secret /etc/openvpn/easy-rsa/2.0/keys/ta.key
这个时候,在keys目录下,产生一个ta.key,同时也需要在server.conf 文件里添加一行

tls-auth /etc/openvpn/easy-rsa/2.0/keys/ta.key 0

要启用这个功能,你还需要把 ta.key 这个文件下载到客户端,并且客户端里的配置文件也需要添加一行


tls-auth  ta.key 1

ll keys/
total 20
-rw-r--r-- 1 root root 1212 Jul 31 12:04 ca.crt
-rw------- 1 root root  887 Jul 31 12:04 ca.key
-rw-r--r-- 1 root root  245 Jul 31 12:08 dh1024.pem
-rw-r--r-- 1 root root    0 Jul 31 12:02 index.txt
-rw-r--r-- 1 root root    3 Jul 31 12:02 serial
-rw------- 1 root root  636 Jul 31 12:08 ta.key

四:OpenVPN Server 路由模式 +证书验证和证书+密码

建立OpenVPN Server端的证书和密钥
common name是 server
./pkitool --server server
# ll keys/
total 44
-rw-r--r-- 1 root root 3863 Jul 26 02:19 01.pem
-rw-r--r-- 1 root root 1212 Jul 26 02:17 ca.crt
-rw------- 1 root root  887 Jul 26 02:17 ca.key
-rw-r--r-- 1 root root  245 Jul 26 02:18 dh1024.pem
-rw-r--r-- 1 root root  105 Jul 26 02:19 index.txt
-rw-r--r-- 1 root root   21 Jul 26 02:19 index.txt.attr
-rw-r--r-- 1 root root    0 Jul 26 02:16 index.txt.old
-rw-r--r-- 1 root root    3 Jul 26 02:19 serial
-rw-r--r-- 1 root root    3 Jul 26 02:16 serial.old
-rw-r--r-- 1 root root 3863 Jul 26 02:19 server.crt
-rw-r--r-- 1 root root  668 Jul 26 02:19 server.csr
-rw------- 1 root root  887 Jul 26 02:19 server.key

建立OpenVPN Client端的证书和密钥
comon name 是 client1
./pkitool client1
# ll keys/
total 68
-rw-r--r-- 1 root root 3863 Jul 26 02:19 01.pem
-rw-r--r-- 1 root root 3747 Jul 26 02:20 02.pem
-rw-r--r-- 1 root root 1212 Jul 26 02:17 ca.crt
-rw------- 1 root root  887 Jul 26 02:17 ca.key
-rw-r--r-- 1 root root 3747 Jul 26 02:20 client1.crt
-rw-r--r-- 1 root root  672 Jul 26 02:20 client1.csr
-rw------- 1 root root  887 Jul 26 02:20 client1.key
-rw-r--r-- 1 root root  245 Jul 26 02:18 dh1024.pem
-rw-r--r-- 1 root root  211 Jul 26 02:20 index.txt
-rw-r--r-- 1 root root   20 Jul 26 02:20 index.txt.attr
-rw-r--r-- 1 root root   21 Jul 26 02:19 index.txt.attr.old
-rw-r--r-- 1 root root  105 Jul 26 02:19 index.txt.old
-rw-r--r-- 1 root root    3 Jul 26 02:20 serial
-rw-r--r-- 1 root root    3 Jul 26 02:19 serial.old
-rw-r--r-- 1 root root 3863 Jul 26 02:19 server.crt
-rw-r--r-- 1 root root  668 Jul 26 02:19 server.csr
-rw------- 1 root root  887 Jul 26 02:19 server.key

创建一个客户端需要输入密码的证书
客户端不但需要证书,还需要密码,而且这个密码,客户端可以自己进行修改。这个倒是非常不错。
-bash-3.2# ./pkitool --pass client2
Generating a 1024 bit RSA private key
......++++++
........++++++
writing new private key to 'client2.key'
Enter PEM pass phrase:                      输入密码
Verifying - Enter PEM pass phrase:
-----
Using configuration from /etc/openvpn/easy-rsa/2.0/openssl.cnf
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
countryName          RINTABLE:'CN'
stateOrProvinceName  RINTABLE:'BJ'
localityName         RINTABLE:'BeiJing'
organizationName     RINTABLE:'iredmail'
commonName           RINTABLE:'client2'
emailAddress          :IA5STRING:'shake.chen@gmail.com'
Certificate is to be certified until Jul 19 12:32:20 2019 GMT (3650 days)

Write out database with 1 new entries
Data Base Updated
ll keys/
total 84
-rw-r--r-- 1 root root 3863 Jul 26 02:19 01.pem
-rw-r--r-- 1 root root 3747 Jul 26 02:20 02.pem
-rw-r--r-- 1 root root 3747 Jul 26 02:21 03.pem
-rw-r--r-- 1 root root 1212 Jul 26 02:17 ca.crt
-rw------- 1 root root  887 Jul 26 02:17 ca.key
-rw-r--r-- 1 root root 3747 Jul 26 02:20 client1.crt
-rw-r--r-- 1 root root  672 Jul 26 02:20 client1.csr
-rw------- 1 root root  887 Jul 26 02:20 client1.key
-rw-r--r-- 1 root root 3747 Jul 26 02:21 client2.crt
-rw-r--r-- 1 root root  672 Jul 26 02:21 client2.csr
-rw------- 1 root root  963 Jul 26 02:21 client2.key
-rw-r--r-- 1 root root  245 Jul 26 02:18 dh1024.pem
-rw-r--r-- 1 root root  317 Jul 26 02:21 index.txt
-rw-r--r-- 1 root root   20 Jul 26 02:21 index.txt.attr
-rw-r--r-- 1 root root   20 Jul 26 02:20 index.txt.attr.old
-rw-r--r-- 1 root root  211 Jul 26 02:20 index.txt.old
-rw-r--r-- 1 root root    3 Jul 26 02:21 serial
-rw-r--r-- 1 root root    3 Jul 26 02:20 serial.old
-rw-r--r-- 1 root root 3863 Jul 26 02:19 server.crt
-rw-r--r-- 1 root root  668 Jul 26 02:19 server.csr
-rw------- 1 root root  887 Jul 26 02:19 server.key

注销证书
这是一个bug,如果你直接注销证书,会出现一个报错,如果你是2.1的版本,就没有这个bug。如果你是使用epel的源,那么不会有这个问题。如果你是用epel,就可以忽略。

Using configuration from /etc/openvpn/easy-rsa/2.0/openssl.cnf
error on line 282 of config file '/etc/openvpn/easy-rsa/2.0/openssl.cnf'

所以需要编辑openssl.cnf 文件,把[ pkcs11_section ]注释掉,就可以了。

# [ pkcs11_section ]
# engine_id = pkcs11
# dynamic_path = /usr/lib/engines/engine_pkcs11.so
# MODULE_PATH = $ENV::PKCS11_MODULE_PATH
# PIN = $ENV::PKCS11_PIN
# init = 0

注销client2证书,

./revoke-full client2

-bash-3.2# ./revoke-full client2
Using configuration from /etc/openvpn/easy-rsa/2.0/openssl.cnf
Revoking Certificate 03.
Data Base Updated
Using configuration from /etc/openvpn/easy-rsa/2.0/openssl.cnf
client2.crt: /C=CN/ST=BJ/L=BeiJing/O=iredmail/CN=client2/emailAddress=shake.chen@gmail.com
error 23 at 0 depth lookup:certificate revoked

这就表示成功,这个时候,就会在keys目录下,产生一个文件crl.pem,这个文件就保存着注销掉客户端的名字,我们还需要在server.conf 文件里添加

crl-verify /etc/openvpn/crl.pem

这个时候,你的客户端就再也不能连接。

注意,如果你的证书是放在这个目录下/etc/openvpn/easy-rsa/2.0/keys/crl.pem,那么会出现没有权限读取的log报错,只能把这个文件放到 /etc/openvpn/crl.pem目录下就可以。
ll keys/
total 96
-rw-r--r-- 1 root root 3863 Jul 31 12:09 01.pem
-rw-r--r-- 1 root root 3747 Jul 31 12:09 02.pem
-rw-r--r-- 1 root root 3747 Jul 31 12:09 03.pem
-rw-r--r-- 1 root root 1212 Jul 31 12:04 ca.crt
-rw------- 1 root root  887 Jul 31 12:04 ca.key
-rw-r--r-- 1 root root 3747 Jul 31 12:09 client1.crt
-rw-r--r-- 1 root root  672 Jul 31 12:09 client1.csr
-rw------- 1 root root  887 Jul 31 12:09 client1.key
-rw-r--r-- 1 root root 3747 Jul 31 12:09 client2.crt
-rw-r--r-- 1 root root  672 Jul 31 12:09 client2.csr
-rw------- 1 root root  963 Jul 31 12:09 client2.key
-rw-r--r-- 1 root root  516 Jul 31 12:10 crl.pem
-rw-r--r-- 1 root root  245 Jul 31 12:08 dh1024.pem
-rw-r--r-- 1 root root  330 Jul 31 12:10 index.txt
-rw-r--r-- 1 root root   20 Jul 31 12:10 index.txt.attr
-rw-r--r-- 1 root root   20 Jul 31 12:09 index.txt.attr.old
-rw-r--r-- 1 root root  317 Jul 31 12:09 index.txt.old
-rw-r--r-- 1 root root 1728 Jul 31 12:10 revoke-test.pem
-rw-r--r-- 1 root root    3 Jul 31 12:09 serial
-rw-r--r-- 1 root root    3 Jul 31 12:09 serial.old
-rw-r--r-- 1 root root 3863 Jul 31 12:09 server.crt
-rw-r--r-- 1 root root  668 Jul 31 12:09 server.csr
-rw------- 1 root root  887 Jul 31 12:09 server.key
-rw------- 1 root root  636 Jul 31 12:08 ta.key
启用ip转发,并且配置iptable,实现NAT
假如iptables是刚装好,没有任何的规则。

iptables设置

vi /etc/sysconfig/iptables

#openvpn
-A INPUT -p udp -m multiport --dport 1194 -j ACCEPT
vi /etc/init.d/openvpn

#Uncomment this line (about line 121)
echo 1 > /proc/sys/net/ipv4/ip_forward
#Add these lines below it, changing 66.160.197.199to your public IP address,
iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -j SNAT --to 66.160.197.199

service openvpn restart

service iptables restart

设置log

建立配置文件中指定的日志文件,并赋予正确的权限
touch /var/log/openvpn.log
touch /var/log/openvpn-status.log
chown nobody.nobody /var/log/openvpn.log
chown nobody.nobody /var/log/openvpn-status.log

设置client-config-dir ccd
如果不进行这个设置,log会报错,
Thu Jul 30 09:04:02 2009 client1/61.49.255.21:2512 MULTI: bad source address from client [192.168.1.120], packet dropped
下面的route的网段,就是客户端所在网段。
cd /etc/openvpn
mkdir ccd
cd ccd
vi client1

iroute 192.168.1.0 255.255.255.0

OpnVPN Server端的主配置文件
openvpn 所有设置都在这个文件
cd /etc/openvpn/
cp /usr/share/doc/openvpn-2.1/sample-config-files/server.conf /etc/openvpn/
vi server.conf
看附录

客户端
把证书压缩,下载到本地,可以使用sz来下载。
注意:如果启用防止dos攻击的功能,需要把ta.key 也下载,每个客户端都需要包含这个文件,并且客户端的配置文件也需要添加。
cp /usr/share/doc/openvpn-2.0.9/sample-config-files/client.conf /etc/openvpn/easy-rsa/2.0/keys/client.ovpn
cd /etc/openvpn/easy-rsa/2.0/keys
zip client1.zip ca.crt client1.crt client1.key client.ovpn
sz client1.zip

修改client.ovpn文件
remote mail.18demo.com 1194

cert client1.crt
key client1.key

#tls-auth  ta.key 1

五:OpenVPN Server 路由模式 +mysql 验证
OpenVPN的用户登录验证是这样的
OpenVPN--->openvpn-auth-pam.so--->PAM--->Mysql/LDAP

rpm -Uhv http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-3.noarch.rpm # <-- For i386
rpm -Uhv http://download.fedora.redhat.com/pub/epel/5/x86_64/epel-release-5-3.noarch.rpm # <-- For x86_64
安装软件
需要让mysql支持pam的验证


检查saslauthd是否安装

rpm -qa | grep cyrus-sasl
yum install cyrus-sasl

安装pam_mysql 让mysql支持pam认证
目前pam_mysql 已经有rpm包,不过目前我只能添加http://rpm.pbone.net 通过这个源来安装,还没有找到合适的源。

yum install pam_mysql

service mysqld restart

安装pam-devel, 如果没有这个,log里会出现

AUTH-PAM: BACKGROUND: could not load PAM lib libpam.so: libpam.so: cannot open shared object file: No such file or directory

导致你无法启动openvpn
yum install pam-devel
创建数据库
我们创建一个vpn的数据库,管理员的用户名:vpn,密码:vpn123
并且创建一个用户elm,密码也是elm,密码采用MD5加密。

mysql -uroot -p
create database vpn;
GRANT ALL ON vpn.* TO vpn@localhost IDENTIFIED BY 'vpn123';
flush privileges;
use vpn;

CREATE TABLE vpnuser (
name char(20) NOT NULL,
password char(128) default NULL,
active int(10) NOT NULL DEFAULT 1,
PRIMARY KEY (name)
);
INSERT INTO vpnuser( name,
PASSWORD )
VALUES (
'elm', md5('elm')
);
配置pam_mysql模块
需要注意到是crypt=3这个参数的设置,表示数据库密码是使用MD5加密。

这里如果你设置crypt=2,使用mysql的 password的函数来加密,会出现用户无法登陆。具体原因是Mysql 的 password 函数因为 mysql 的加密函数和 pam_mysql的加密函数不相同。
0 = 明文
1 = Use crypt
2 = Use MySQL PASSWORD() function
3 = md5

vi /etc/pam.d/openvpn

auth sufficient pam_mysql.so user=vpn passwd=vpn123 host=localhost db=vpn \
table=vpnuser usercolumn=name passwdcolumn=password \
where=active=1 sqllog=0 crypt=3
account required pam_mysql.so user=vpn passwd=vpn123 host=localhost db=vpn \
table=vpnuser usercolumn=name passwdcolumn=password \
where=active=1 sqllog=0 crypt=3
修改server和客户端文件

server 文件
plugin /usr/share/openvpn/plugin/lib/openvpn-auth-pam.so openvpn
client-cert-not-required
username-as-common-name

客户端
配置客户端配置文件

注释掉

;cert client1.crt

;key client1.key

增加

#询问用户名和密码

auth-user-pass

这个时候,你就可以用
user:elm
pass:elm
登录openvpn
六:OpenVPN Server 路由模式 + 文本口令认证


下载脚本

wget http://openvpn.se/files/other/checkpsw.sh -P /etc/openvpn
cd /etc/openvpn
chmod u+x checkpsw.sh
chown nobody.nobody checkpsw.sh

创建 /etc/openvpn/psw-file
格式:用户名Tab密码

user1 pass
user2 pass

在server.conf 配置文件里加上

auth-user-pass-verify /etc/openvpn/checkpsw.sh via-env
客户端的修改和上面一样。

注释掉

;cert client1.crt

;key client1.key

增加

#询问用户名和密码

auth-user-pass

这个时候就可以登录,不过注意,mysql和text方式的验证,好像只能选择一种。

七:OpenVPN Server 路由模式 + POP认证

原理和text基本一样。

vi /etc/openvpn/popauth.pl

chmod +x /etc/openvpn/popauth.pl

在server文件里,添加

auth-user-pass-verify /etc/openvpn/popauth.pl via-env

下面就是popauth.pl
#!/usr/bin/perl
# Write by ELM
# wzk [A|T] wenzk [D|O|T] net
# http://www.wenzk.net
#
# POP3 Auth script for OpenVPN
# Usage:
# save this file to /etc/openvpn/ as popauth.pl
# run: chmod +x /etc/openvpn/popauth.pl
# add the next line to you OpenVPN config file
# auth-user-pass-verify /etc/openvpn/popauth.pl via-env
# restart your OpenVPN Server

use Net::POP3;

# POP Server Address
$POPHOST = "localhost";
$USERNAME = $ENV{username};
$PASSWORD = $ENV{password};

# Constructors
$pop = Net::POP3->new($POPHOST);
$pop = Net::POP3->new($POPHOST, Timeout => 60);


if ( defined  $pop->login($USERNAME, $PASSWORD) ) {
        $result = 0;
} else {
        $result = 1;
}

$pop->quit;

exit $result;

八:ldap验证

yum install openvpn-auth-ldap
<LDAP>
    # LDAP server URL
    URL     ldap://mail.18demo.com

    # Bind DN (If your LDAP server doesn't support anonymous binds)
    # BindDN        uid=Manager,ou=People,dc=example,dc=com
     BindDN     cn=manager,dc=18demo,dc=com

    # Bind Password
    # Password  SecretPassword
     Password   iredmail

    # Network timeout (in seconds)
    Timeout     15 

    # Enable Start TLS
    #TLSEnable  yes
    TLSEnable   no 

    # Follow LDAP Referrals (anonymously)
    #FollowReferrals yes

    # TLS CA Certificate File
    #TLSCACertFile  /usr/local/etc/ssl/ca.pem

    # TLS CA Certificate Directory
    #TLSCACertDir   /etc/ssl/certs

    # Client Certificate and key
    # If TLS client authentication is required
    #TLSCertFile    /usr/local/etc/ssl/client-cert.pem
    #TLSKeyFile /usr/local/etc/ssl/client-key.pem

    # Cipher Suite
    # The defaults are usually fine here
    # TLSCipherSuite    ALL:!ADH:@STRENGTH
</LDAP>

<Authorization>
    # Base DN
    #BaseDN     "ou=People,dc=example,dc=com"
    BaseDN      "domainName=18demo.com,o=domains,dc=18demo,dc=com"

    # User Search Filter
    #SearchFilter   "(&(uid=%u)(accountStatus=active))"
    SearchFilter    "(accountStatus=active)"

    # Require Group Membership
    RequireGroup    false

    # Add non-group members to a PF table (disabled)

# Add non-group members to a PF table (disabled)
    #PFTable    ips_vpn_users

    <Group>
        BaseDN      "ou=Groups,dc=example,dc=com"
        SearchFilter    "(|(cn=developers)(cn=artists))"
        MemberAttribute uniqueMember
        # Add group members to a PF table (disabled)
        #PFTable    ips_vpn_eng
    </Group>
</Authorization>
                             
需要pam-ldap.so模块,在centos下,我们需要安装nss_ldap

yum install nss_ldap
cp /usr/share/doc/nss_ldap-253/ldap.conf.pam_ldap /etc/pam_ldap.conf
create /etc/pam.d/openvpn
auth required /lib/security/pam_ldap.so
account required /lib/security/pam_ldap.so

http://www.nabble.com/openvpn-auth-pam.so,-pam_ldap-td9858335.html

四:附录
server.conf配置文件
port 1194
proto udp
dev tun
ca /etc/openvpn/easy-rsa/2.0/keys/ca.crt
cert /etc/openvpn/easy-rsa/2.0/keys/server.crt
key /etc/openvpn/easy-rsa/2.0/keys/server.key  # This file should be kept secret
dh /etc/openvpn/easy-rsa/2.0/keys/dh1024.pem
;crl-verify /etc/openvpn/easy-rsa/2.0/keys/crl.pem
server 10.8.0.0 255.255.255.0
ifconfig-pool-persist ipp.txt
client-config-dir ccd
route 192.168.1.0 255.255.255.0
push "redirect-gateway def1"
;push "dhcp-option DNS 10.8.0.1"
;push "dhcp-option WINS 10.8.0.1"
;client-to-client
;duplicate-cn
keepalive 10 120
;tls-auth /etc/openvpn/easy-rsa/2.0/keys/ta.key 0
comp-lzo
;max-clients 100
user nobody
group nobody
persist-key
persist-tun
status /var/log/openvpn-status.log
log-append        /var/log/openvpn.log
verb 3
mute 20

#pop auth
#auth-user-pass-verify /etc/openvpn/popauth.pl via-env
#text auth
#auth-user-pass-verify /etc/openvpn/checkpsw.sh via-env
#pam auth
#plugin /usr/share/openvpn/plugin/lib/openvpn-auth-pam.so openvpn
client-cert-not-required
username-as-common-name

iptables设置

通过输入命令iptables-save >

通过输入iptables-restore <

保存对防火墙的设置并重新启动防火墙
#service iptables save
#service iptables restar

/usr/lib64/openvpn/plugin/lib/openvpn-auth-ldap.so
参考文章

http://www.xiaohui.com/dev/server/20070514-install-openvpn.htm

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics