2653885 发表于 2019-1-27 06:27:24

2、CentOS6.5 安装Open×××使用easy

  1、安装eple源
yum install -y epel-release
sed -i 's/mirrorlist=https/mirrorlist=http/g' /etc/yum.repos.d/epel.repo**
  2、安装openssl和lzo
yum install -y openssl openssl-devel lzo lzo-devel pam pam-devel automake pkgconfig
  3、安装open
yum install -y open easy-rsa
  4、配置easy-rsa
cp -r /usr/share/easy-rsa/3.0.3/ /etc/open/easy-rsa
cp /usr/share/doc/easy-rsa-3.0.3/vars.example /etc/open/easy-rsa/vars
  grep ^set /etc/open*/easy-rsa/vars
set_var EASYRSA_REQ_COUNTRY   "CN"                                       #国家
set_var EASYRSA_REQ_PROVINCE    "Guangdong"         #省
set_var EASYRSA_REQ_CITY      "Shenzhen"                         #城市
set_var EASYRSA_REQ_ORG               "IT"                                          #组织
set_var EASYRSA_REQ_EMAIL       "IT@example.net"      #邮箱
set_var EASYRSA_REQ_OU          "IT"                                             #公司、组织
  5、制作CA证书(证书存放目录/etc/open/easy-rsa/pki/ca.crt)
cd /etc/open/easy-rsa/
./easyrsa init-pki                                          #初始化pki,生成目录文件结构
./easyrsa build-ca                                    #在Enter PEM pass phrase:处设置CA密码,其他直接回车
  6、制作服务器端证书、证书签名(证书存放目录/etc/open*/easy-rsa/pki/issued/server.crt)
./easyrsa gen-req server nopass                     #一路回车即可
./easyrsa sign server server                                 #此过程需要输入yes和CA密码
  7、制作dh证书(证书存放目录/etc/open*/easy-rsa/pki/dh.pem)
./easyrsa gen-dh
  8、生成ta秘钥
cd /etc/open
open --genkey --secret ta.key
  9、制作客户端证书、证书签名
cp -r /usr/share/easy-rsa/3.0.3/ /etc/open/client
cp /usr/share/doc/easy-rsa-3.0.3/vars.example /etc/open/client/vars
cd /etc/open*/client
./easyrsa init-pki                                                #初始化pki,生成目录文件结构
./easyrsa gen-req client nopass                         #一路回车即可
  cd /etc/open/easy-rsa
./easyrsa import-req /etc/open/client/pki/reqs/client.req client
./easyrsa sign client client                                       #此过程需要输入yes和CA密码
  10、修改服务器端配置文件
cp /etc/open/easy-rsa/pki/ca.crt /etc/open/
cp /etc/open/easy-rsa/pki/private/server.key /etc/open/
cp /etc/open/easy-rsa/pki/issued/server.crt /etc/open/
cp /etc/open/easy-rsa/pki/dh.pem /etc/open/
cp /usr/share/doc/open-2.4.6/sample/sample-config-files/server.conf /etc/open/
  cat /etc/open/server.conf
local 0.0.0.0                                                                           #指定监听的IP地址
port 1194                                                                         #指定监听的端口
proto tcp                                                                         #指定使用的协议
dev tun                                                                            #指定采用路由隧道模式
ca ca.crt                                                                        #ca证书相对路径,相对路径要与server.conf在同一目录
cert server.crt                                                               #服务端证书相对路径
key server.key                                                                #服务端key相对路径
dh dh.pem                                                                  #dh密钥相对路径
server 10.8.0.0 255.255.255.0                         #给客户端分配的地址池
ifconfig-pool-persist ipp.txt                                 #定义客户端和虚拟ip地址之间的关系,特别是在open重启时,再次连接的客户端将依然被分配和断开之前的IP地址。
push "redirect-gateway def1 bypass-dhcp"#客户端出口显示为服务器的IP地址
push "dhcp-option DNS 8.8.8.8"                  #指定dns
push "dhcp-option DNS 114.114.114.114"      #指定dns
push "route 10.2.1.0 255.255.255.0"                            #实际想要访问的内网IP段
push "route 172.16.1.0 255.255.255.0"                        #实际想要访问的内网IP段
client-to-client                                                                     #客户端之间能相互访问
duplicate-cn                                                                            #客户端都使用相同的证书和密钥连接×××,一定要打开这个选项,否则每个证书只允许一个人连接×××
keepalive 10 120                                                #心跳检测,10秒检测一次,2分钟内没有回应则视为断线
tls-auth ta.key 0                                                 #开启TLS,使用ta.key防御×××。服务器端的第二个参数值为0,客户端的为1。
cipher AES-256-CBC
comp-lzo                                                                     #传输数据压缩
persist-key                                                                            #通过keepalive检测超时后,重新启动×××,不重新读取keys,保留第一次使用的keys
persist-tun                                                                            #通过keepalive检测超时后,重新启动×××,一直保持tun或者tap设备是linkup的。否则网络连接,会先linkdown然后再linkup。
status open-status.log                                       #Open×××的状态日志,默认为/etc/open/open-status.log
log-append open.log                                             #Open×××的运行日志,默认为/etc/open/open.log
verb 5                                                                                     #改成verb 5可以多查看一些调试信息
  11、修改客户端配置文件
cp /usr/share/doc/open-2.4.6/sample/sample-config-files/client.conf /etc/open/client/client.o
cat /etc/open/client/client.o*                                                                  
client
dev tun
proto tcp
remote 10.1.1.1 1194
resolv-retry infinite
nobind
persist-key
persist-tun
remote-cert-tls server
ca ca.crt
cert client.crt
key client.key
tls-auth ta.key 1
cipher AES-256-CBC
comp-lzo
verb 5
  12、开启路由转发,配置防火墙,启动服务
sed -i '/net.ipv4.ip_forward/s/0/1/' /etc/sysctl.conf
sysctl -p
  iptables -I INPUT -p tcp --dport 1194 -m comment --comment "open*" -j ACCEPT
iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -j MASQUERADE
service iptables save
  service open start
chkconfig open on
  13、客户端需要的文件
/etc/open/easy-rsa/pki/issued/client.crt
/etc/open/client/pki/private/client.key
/etc/open/easy-rsa/pki/ca.crt
/etc/open/ta.key
/etc/open/client/client.o
  sz /etc/open/easy-rsa/pki/issued/client.crt    /etc/open/client/pki/private/client.key    /etc/open/easy-rsa/pki/ca.crt/etc/open/ta.key   /etc/open/client/client.o
  14、查看登录日志
cat open*.log |grep "primary virtual IP"
  **
  15、更改为使用账号密码自动登录
  在/etc/open***/server.conf末尾添加下面四行
auth-user-pass-verify /etc/open***/checkpwd.sh via-env#用户密码认证脚本
client-cert-not-required#关闭证书认证方式
username-as-common-name    #用户登陆
script-security 3    #安全脚本方式认证
  配置用户密码认证脚本,修改文件权限
cat /etc/open***/checkpwd.sh
#!/bin/sh
###########################################################
checkpsw.sh (C) 2004 Mathias Sundman
PASSFILE="/etc/open***/pwd-file"
LOG_FILE="/var/log/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
  chmod +x/etc/open***/checkpwd.sh
  配置用户账号密码文件,修改文件权限
cat /etc/open***/pwd-file
test 123
  chmod 400 pwd-file
chown nobody.nobody pwd-file
  在用户配置文件client.o***末尾添加下面一行,并注释掉cert和key这两行
auth-user-pass pwd.txt
  pwd.txt的内容如下,第一行为账号,第二行为密码
test
123



页: [1]
查看完整版本: 2、CentOS6.5 安装Open×××使用easy