# 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. LeetCode 495. Teemo Attacking (提莫攻击)

    In LOL world, there is a hero called Teemo and his attacking can make his enemy Ashe be in poisoned ...

  2. Bootstrap的核心——栅格系统的使用

        前  言 絮叨絮叨 Bootstrap 是基于 HTML.CSS.JAVASCRIPT 的,它简洁灵活,使得 Web 开发更加快捷. 而栅格系统是Bootstrap中的核心,正是因为栅格系统的 ...

  3. JSON.stringify实战用法

    1.首先定义一个数组 var teamPlanMinList = new Array(); 2. 定义一个json对象 var json = { "plname":plname, ...

  4. 编程&blog处女篇-用C#求100以内的质数

    using System;namespace Loops{ class Program { static void Main(string[] args) { /*局部变量定义*/ int i, j; ...

  5. C++ 中memset 勿要对类使用

    C++ 中memset 勿要对类使用 参考链接: http://www.cppblog.com/qinqing1984/archive/2009/08/07/92479.html 百度百科第一次这么给 ...

  6. kettle介绍

    Kettle也叫PDI,在2006年Kettle加入了开源的BI组织Pentaho,正式命名为PDI,英文全称为Pentaho Data Integeration.Kettle是"Kettl ...

  7. 【Win 10 应用开发】UI Composition 札记(三):与 XAML 集成

    除了 DirectX 游戏开发,我们一般很少单独使用 UI Composition ,因此,与 XAML 互动并集成是必然结果.这样能够把两者的优势混合使用,让UI布局能够更灵活. 说到与 XAML ...

  8. ajax请求发送和页面跳转的冲突

    http://blog.csdn.net/allenliu6/article/details/77341538?locationNum=7&fps=1 在A页面中,有一个click事件,点击时 ...

  9. server-sent-event使用流信息向客户端发送数据

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  10. 从运维的角度分析使用阿里云数据库RDS的必要性--你不应该在阿里云上使用自建的MySQL/SQL Server/Oracle/PostgreSQL数据库

    开宗明义,你不应该在阿里云上使用自建的MySQL or SQL Server数据库,对了,还有Oracle or PostgreSQL数据库. 云数据库 RDS(Relational Database ...