Open***使用用户密码认证登录

前面写到了Centos7安装Open×××,为了安全和方便管理,下面介绍如何采取用户认证的方式连接到open***服务器。

修改open***配置文件
vi /etc/open***/server.conf #编辑/etc/server.conf文件,并添加如下内容:
script-security 3 #允许通过环境变量将密码传递给脚本
auth-user-pass-verify /etc/open***/checkpsw.sh via-env #指定checkpsw.sh位置,提供一个用户名密码对
client-cert-not-required #不使用客户端证书,使用密码对
username-as-common-name #使用认证用户名,不使用证书的common name
下载用户验证脚本:checkpsw.sh,链接:https://pan.baidu.com/s/14KSA0S8A5dwgYGQR-CX5iQ 密码:315

!/bin/bash
*# This script will authenticate Open××× users against
a plain text file. The passfile should simply contain
one row per user with the username first followed by
one or more space(s) or tab(s) and then the password.
PASSFILE="/etc/open***/psw-file"
LOG_FILE="/etc/open***/login-auth.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
# using th re(Regular Expressions)
#CORRECT_PASSWORD=`awk '!/^;/&&!/^#/&&$1=="${username}"{print $2;exit}' ${PASSFILE}`
CORRECT_PASSWORD=$(grep -oP "(?<=^$username\s).+$" $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

创建用户名密码文件

cp /root/checkpw.sh /etc/open***/ #把下载的checkpsw.sh拷贝到/etc/server.conf中指定的位置
chmod +x /etc/open***/checkpw.sh # 给脚本添加执行权限
# 给脚本添加执行权限,并将脚本拷贝到/etc/server.conf中指定的位置
touch /etc/open***/login-auth.log
chmod 755 login-auth.log
# 创建日志文件,用来记录用户名密码认证产生的日志
echo "test 123456" >>/etc/open***/psw-file
chmod 400 /etc/open***/psw-file
chown nobody:nobody psw-file
# 创建用户名密码文件,并修改权限
[root@open*** ~]# ll /etc/open***/psw-file 
-r-------- 1 root root 12 Sep 21 02:35 /etc/open***/psw-file
[root@open*** ~]# cat /etc/open***/psw-file 
test 123456

修改客户端配置文件
注释掉cert和key(客户端不需要crt和key文件,但是需要服务器的CA证书)
;cert eva.crt
;key eva.key
添加如下内容
auth-user-pass
客户端文件示例

client
#定义这是一个client,配置从server端pull拉取过来,如IP地址,路由信息之类,Server使用push指令推送过来。
dev tun
#定义open***运行的模式,这个地方需要严格和Server端保持一致。
proto tcp
#定义open***使用的协议,这个地方需要严格和Server端保持一致。
remote 10.1.2.80 1194
#设置Server的IP地址和端口,这个地方需要严格和Server端保持一致。
resolv-retry infinite
#始终重新解析Server的IP地址(如果remote后面跟的是域名),保证Server IP地址是动态的使用DDNS动态更新DNS后
#Client在自动重新连接时重新解析Server的IP地址。这样无需人为重新启动,即可重新接入×××。
nobind
#定义在本机不邦定任何端口监听incoming数据。
persist-key
persist-tun
ca ca.crt
#定义CA证书的文件名,用于验证Server CA证书合法性,该文件一定要与服务器端ca.crt是同一个文件。
;cert client.crt
#定义客户端的证书文件
;key client.key
#定义客户端的密钥文件。
comp-lzo
#启用允许数据压缩,这个地方需要严格和Server端保持一致
verb 3
#设置日志要记录的级别。
auth-user-pass #使用用户名密码登录open***服务器

转载于:https://blog.51cto.com/terry520/2106727

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值