# openVPN+LDAP AD认证,组权限管理

原创内容http://www.cnblogs.com/elvi/p/7661178.html

# openVPN+LDAP AD认证,组权限管理

#环境 centos6
#关闭selinux、防火墙
#vim /etc/sysconfig/network #修改hostname
#vim /etc/hosts #添加hostname名称

#更换阿里源
yum -y install wget vim
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
#安装epel包
#yum install epel-release #EPEL源
yum -y install http://mirrors.ustc.edu.cn/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm
yum makecache #生成缓存

ntpdate ntp.shu.edu.cn ##同步时间

# 安装openssl和lzo,lzo用于压缩通讯数据加快传输速度
#yum -y install openssl openssl-devel
#yum -y install lzo
#yum -y install openvpn easy-rsa # 安装openvpn和easy-rsa
yum -y install openssl openssl-devel lzo openvpn easy-rsa

# 修改vars文件
cd /usr/share/easy-rsa/2.0/
cp vars vars.bak
vim vars
    # 修改注册信息,比如公司地址、公司名称、部门名称等。
    export KEY_COUNTRY="CN"
    export KEY_PROVINCE="ShangHai"
    export KEY_CITY="ShangHai"
    export KEY_ORG="elven"
    export KEY_EMAIL="me@elven.me"
    export KEY_OU="elven"
# 初始化环境变量
source vars
# 清除keys目录下所有与证书相关的文件
./clean-all
# 生成根证书ca.crt和根密钥ca.key(一路按回车即可,存放目录/usr/share/easy-rsa/2.0/keys)
./build-ca
# 服务端证书和密钥(一路按回车,提示y/n时,输入y再按回车,一共两次)
./build-key-server server
# 为客户端生成证书和密钥(一路按回车,提示y/n时,输入y再按回车,一共两次)
./build-key client
# 创建迪菲·赫尔曼密钥,会生成dh2048.pem文件(生成过程慢,不要去中断它)
./build-dh
# 生成ta.key文件(防DDos攻击、UDP淹没等恶意攻击)
openvpn --genkey --secret keys/ta.key

###创建服务器端配置文件
# 在openvpn的配置目录下新建一个keys目录
mkdir /etc/openvpn/keys
# 将需要用到的openvpn证书和密钥复制一份到刚创建好的keys目录中
cp /usr/share/easy-rsa/2.0/keys/{ca.crt,server.{crt,key},dh2048.pem,ta.key} /etc/openvpn/keys
# 复制一份服务器端配置文件模板server.conf到/etc/openvpn/
cp /usr/share/doc/openvpn-*/sample/sample-config-files/server.conf /etc/openvpn/
# 查看server.conf里的配置参数
grep '^[^#;]' /etc/openvpn/server.conf
# 编辑server.conf
cp /etc/openvpn/server.conf /etc/openvpn/server.conf.bak
vim /etc/openvpn/server.conf
    #--------
    port
    proto tcp
    dev tun
    ca keys/ca.crt
    cert keys/server.crt
    key keys/server.key  # This file should be kept secret
    dh keys/dh2048.pem
    server 192.168.98.0 255.255.255.0 #虚拟网段
    ifconfig-pool-persist ipp.txt
    push "route 192.168.98.0 255.255.255.0"
    push "route 192.168.0.0 255.255.255.0"
    push "route 172.16.11.0 255.255.255.0"
    push "dhcp-option DNS 172.16.11.12"
    push "dhcp-option DNS 172.16.11.14"
    ;push "redirect-gateway def1 bypass-dhcp"  #使客户端所有网络通信通过vpn
    client-to-client
    duplicate-cn
    keepalive
    tls-auth keys/ta.key  # This file is secret
    comp-lzo
    persist-key
    persist-tun
    status openvpn-status.log
    log-append openvpn.log
    verb
    #--------

###配置内核和防火墙,启动服务
# 开启路由转发功能
sysctl -
sed -i '/net.ipv4.ip_forward/s/0/1/' /etc/sysctl.conf
sysctl -p
# 配置防火墙,别忘记保存
iptables -I INPUT -p tcp --dport  -m comment --comment "openvpn" -j ACCEPT
iptables -t nat -A POSTROUTING -s  -j MASQUERADE
service iptables save

# 启动openvpn并设置为开机启动
service openvpn start
chkconfig openvpn on
netstat -anpt |grep vpn #查看网络端口
#service iptables restart
#service openvpn restart

#客户端配置文件
#cp /usr/share/doc/openvpn-*/sample/sample-config-files/client.conf client.ovpn
vim /etc/openvpn/client.ovpn
    # client.ovpn
    client
    dev tun
    proto tcp
    #remote
    remote
    resolv-retry infinite
    nobind
    persist-key
    persist-tun
    ca ca.crt
    #cert client.crt
    #key client.key
    remote-cert-tls server
    tls-auth ta.key
    comp-lzo
    verb
    auth-user-pass #密码认证

########################
# 开启客户端
openvpn /etc/openvpn/client.ovpn &
pkill openvpn #关闭进程

#client keys
mkdir /etc/openvpn/kk
# 客户端需要的证书复制到刚创建好的目录
cp /usr/share/easy-rsa/2.0/keys/{ca.crt,client.{crt,key},ta.key} /etc/openvpn/kk

#Windows客户端
#将OpenVPN服务器上的client.ovpn、ca.crt、client.crt、client1.key、ta.key上传到Windows客户端安装目录下的config文件夹

#############Ldap  openvpn-auth-ldap认证(推荐)
cd /etc/openvpn
yum install openvpn-auth-ldap -y
vi /etc/openvpn/auth/ldap.conf
    #---
    ### OpenVPN LDAP 认证
    <LDAP>
    URL ldap://172.16.11.14:389
    #认证用户密码
    BindDN "CN=ldap,OU=Dev,OU=Tech,OU=XLH_users,DC=test,DC=cn"
    password "
    #设置网络超时时间
    Timeout
    TLSEnable no
    FollowReferrals no
    </LDAP>
    <Authorization>
    BaseDN "DC=test,DC=cn"
    SearchFilter "(&(sAMAccountName=%u)(memberof=CN=vpn,OU=role,OU=XLH_users,DC=test,DC=cn))"
    #SearchFilter "(sAMAccountName=%u)"
    RequireGroup false
    #使用AD组权限
    <Group>
    BaseDN "OU=role,OU=XLH_users,DC=test,DC=cn"
    SearchFilter "(|(cn=vpn))"
    #MemberAttribute "member"
    MemberAttribute uniqueMember
    </Group>
    </Authorization>
    #---
vim /etc/openvpn/server.conf
# openvpn-auth-ldap
    plugin /usr/lib64/openvpn/plugin/lib/openvpn-auth-ldap.so "/etc/openvpn/auth/ldap.conf cn=%u"
    client-cert-not-required
    username-as-common-name
service openvpn restart
##############################################
#@ checkpsw.sh  密码文件认证
vim /etc/openvpn/checkpsw.sh
##
chmod +x /etc/openvpn/checkpsw.sh
vim /etc/openvpn/psw-file
aa1 qq1
 vim /etc/openvpn/psw-file
vim /etc/openvpn/server.conf
    # ---- checkpsw.sh
    script-security  system
    auth-user-pass-verify /etc/openvpn/checkpsw.sh via-env
    client-cert-not-required
    username-as-common-name
service openvpn restart
##############################################
#合并证书到配置文件中,仅供参考
vim client.ovpn
#ca ca.crt 注释证书文件
#在最后面添加以下内容:
</key>
key-direction
<tls-auth>
ta.key文件内容
</tls-auth>
################ Python脚本 Ldap 认证
cd /etc/openvpn
echo elven >>/etc/openvpn/authfile.conf #openvpn Ldap授权用户文件
echo test2 >/etc/openvpn/user.conf  #Ldap认证用户
echo w1w1 >>/etc/openvpn/user.conf
#yum install python-ldap
vim /etc/openvpn/check_credit.py
 #openvpn-Ldap.py
chmod +x /etc/openvpn/check_credit.py
python check_credit.py user.conf 

vim /etc/openvpn/server.conf
# openvpn-Ldap.py
auth-user-pass-verify /etc/openvpn/check_credit.py via-file
client-cert-not-required
username-as-common-name
script-security
##############################################

# openVPN+LDAP AD认证,组权限管理的更多相关文章

  1. Spark SQL Thrift Server 配置 Kerberos身份认证和权限管理

    转载请注明出处:http://www.cnblogs.com/xiaodf/ 之前的博客介绍了通过Kerberos + Sentry的方式实现了hive server2的身份认证和权限管理功能,本文主 ...

  2. springboot(十四):springboot整合shiro-登录认证和权限管理

    这篇文章我们来学习如何使用Spring Boot集成Apache Shiro.安全应该是互联网公司的一道生命线,几乎任何的公司都会涉及到这方面的需求.在Java领域一般有Spring Security ...

  3. Springboot-shiro-redis实现登录认证和权限管理

    Springboot-shiro-redis实现登录认证和权限管理 在学习之前: 首先进行一下Apache Shiro和Shiro比较: Apache Shiro是一个功能强大.灵活的,开源的安全框架 ...

  4. Spring boot 入门(四):集成 Shiro 实现登陆认证和权限管理

    本文是接着上篇博客写的:Spring boot 入门(三):SpringBoot 集成结合 AdminLTE(Freemarker),利用 generate 自动生成代码,利用 DataTable 和 ...

  5. spring-boot(八) springboot整合shiro-登录认证和权限管理

    学习文章:springboot(十四):springboot整合shiro-登录认证和权限管理 Apache Shiro What is Apache Shiro? Apache Shiro是一个功能 ...

  6. (转)Spring Boot (十四): Spring Boot 整合 Shiro-登录认证和权限管理

    http://www.ityouknow.com/springboot/2017/06/26/spring-boot-shiro.html 这篇文章我们来学习如何使用 Spring Boot 集成 A ...

  7. Spring Boot(十四):spring boot整合shiro-登录认证和权限管理

    Spring Boot(十四):spring boot整合shiro-登录认证和权限管理 使用Spring Boot集成Apache Shiro.安全应该是互联网公司的一道生命线,几乎任何的公司都会涉 ...

  8. spring boot(十四)shiro登录认证与权限管理

    这篇文章我们来学习如何使用Spring Boot集成Apache Shiro.安全应该是互联网公司的一道生命线,几乎任何的公司都会涉及到这方面的需求.在Java领域一般有Spring Security ...

  9. Spring Cloud之路:(七)SpringBoot+Shiro实现登录认证和权限管理

    版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/sage_wang/article/details/79592269一.Shiro介绍1.Shiro是 ...

随机推荐

  1. 如何把项目上传到GitHub上

    p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 15.0px Consolas; color: #a5b2b9 } span.Apple-tab-span ...

  2. LeetCode 617. Merge Two Binary Tree (合并两个二叉树)

    Given two binary trees and imagine that when you put one of them to cover the other, some nodes of t ...

  3. LeetCode 414. Third Maximum Number (第三大的数)

    Given a non-empty array of integers, return the third maximum number in this array. If it does not e ...

  4. Muduo阅读笔记--base(二)

    上一篇文章对muduo的入门做了介绍. http://www.cnblogs.com/LCCRNblog/p/5668035.html base文件夹下这么多代码,该如何入手呢?对于我这种第一次接触大 ...

  5. Python通过跳板机链接MySQL的一种方法

  6. JAVA提高十二:HashMap深入分析

    首先想说的是关于HashMap源码的分析园子里面应该有很多,并且都是分析得很不错的文章,但是我还是想写出自己的学习总结,以便加深自己的理解,因此就有了此文,另外因为小孩过来了,因此更新速度可能放缓了, ...

  7. Linux系列教程(十七)——Linux权限管理之文件系统系统属性chattr权限和sudo命令

    上篇博客我们介绍了权限管理的ACL权限,通过设定 ACL 权限,我们为某个用户指定某个文件的特定权限.这篇博客我们将介绍权限管理中用的比较多的两个命令 chattr 和 sudo . 1.设定文件系统 ...

  8. NoSQL:linux操作memcached

    缓存数据库 一 NoSQL简介 NoSQL(NoSQL = Not Only SQL ),意即"不仅仅是SQL",泛指非关系型的数据库,随着互联网web2.0网站的兴起,传统的关系 ...

  9. 手工搭建基于ABP的框架(2) - 访问数据库

    为了防止不提供原网址的转载,特在这里加上原文链接: http://www.cnblogs.com/skabyy/p/7517397.html 本篇我们实现数据库的访问.我们将实现两种数据库访问方法来访 ...

  10. Java反射机制使用场景

    import java.io.*; import java.util.Properties; /*问题描述:存在一个主板--已经定义好,不想修改其代码,还想在主板上面增加一些其他功能? *问题解决方法 ...