# 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. 基于webuploader.js的单图片上传封装

    HTML代码 <div class="manageImgUp">点击图片上传</div> <div class="manageImgUpLc ...

  2. SVN.服务器迁移方法

    SVN项目, 源服务器  : 10.10.13.48 目标服务器: 10.10.13.129 要把SVN项目从.48上迁移到.129上. 做法: 准备: 版本库:vos 源服务器  : 10.10.1 ...

  3. MongoDB索引限制

    1. 额外开销: 每个索引占据一定的存储空间,在进行插入,更新和删除操作时也需要对索引进行操作.所以,如果你很少对集合进行读取操作,建议不使用索引. 2. 内存使用: 由于索引是存储在内存(RAM)中 ...

  4. java swing中Timer类的学习

    最近在完成学校课程的java平时作业,要实现一个计时器,包含开始.暂停以及重置三个功能.由于老师规定要用这个timer类,也就去学习了一下,顺便记录一下. 首先呢去查了一下java手册上的东西,发现t ...

  5. 【机器学习】支持向量机(SVM)

    感谢中国人民大学胡鹤老师,课程深入浅出,非常好 关于SVM 可以做线性分类.非线性分类.线性回归等,相比逻辑回归.线性回归.决策树等模型(非神经网络)功效最好 传统线性分类:选出两堆数据的质心,并做中 ...

  6. 深度学习系列 Part(3)

    这是<GPU学习深度学习>系列文章的第三篇,主要是接着上一讲提到的如何自己构建深度神经网络框架中的功能模块,进一步详细介绍 Tensorflow 中 Keras 工具包提供的几种深度神经网 ...

  7. Problem O

    Problem Description Before bridges were common, ferries were used to transport cars across rivers. R ...

  8. 暑假练习赛 003 F Mishka and trip

    F - Mishka and trip Sample Output   Hint In the first sample test: In Peter's first test, there's on ...

  9. 反馈法学习设计模式(一)——策略模式Strategy Pattern

    简介(Introduction) 之前学习Java8实战时,遇到一个很好的策略模式示例.便想着借着这个示例结合反馈式的方法来,学习策略设计模式,也以便后面反复琢磨学习. 首先我们通过练习,逐步写出符合 ...

  10. HashMap面试题:90%的人回答不上来

    在java面试中集合类似乎已经是绕不开的话题,对于一个中高级java程序员来说如果对集合类的内部原理不了解,基本上面试都会被pass掉.下面从面试官的角度来聊聊一个候选者应该对HashMap了解到什么 ...