Centos7+Open***使用用户及密码验证登陆

我们上一篇文章介绍了Centos7+Open***使用证书验证登陆介绍,今天我们介绍Centos7+Open***使用用户及密码登陆验证,具体就补多少了,环境还是基于上一篇的更改来完成。

我们使用Centos7+Open***使用用户及密码登陆验证小下载一个验证脚本来完成用户验证登陆。

http://open***.se/files/other/checkpsw.sh

#!/bin/sh
###########################################################
# checkpsw.sh (C) 2004 Mathias Sundman <mathias@open***.se>
#
# 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="/usr/local/open***/etc/psw-file"
LOG_FILE="/usr/local/open***/var/open***-password.log"
TIME_STAMP=`date "+%Y-%m-%d %T"`
###########################################################
if [ ! -r "${PASSFILE}" ]; thenecho "${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

我们然后进入open***的配置目录

cd /etc/open***/
vi checkpsw.sh

然后将脚本文件粘贴,然后需要修改PASSFILE和LOG_FILE的路劲,根据自己的真是路劲修改

保存退出,然后我们需要修改open***的server.conf 文件,然后添加以下配置字段

auth-user-pass-verify /etc/open***/userauthdir/checkpsw.sh via-env   开启用户密码脚本:
client-cert-not-required        取消客户端的证书认证:
username-as-common-name   不要求客户端有证书
script-security 3   system                    消除以下警告

我们在修改前先看看上一篇的配置文件内容

我们为了更好的体现配置,将原来的server.conf文件进行过滤注释的内容,然后拷贝出来新建一个server.conf文件,然后将没有注释的内容添加到新建的server.conf文件中这样为了更好的配置和拍错。

我们上一节是在默认的server.conf文件里面直接修改的,所以我们需要将没有注释的内容过滤出来,我们先看看默认的配置文件内容

[root@open*** open***]# cat server.conf
#################################################
# Sample Open××× 2.0 config file for            #
# multi-client server.                          #
#                                               #
# This file is for the server side              #
# of a many-clients <-> one-server              #
# Open××× configuration.                        #
#                                               #
# Open××× also supports                         #
# single-machine <-> single-machine             #
# configurations (See the Examples page         #
# on the web site for more info).               #
#                                               #
# This config should work on Windows            #
# or Linux/BSD systems.  Remember on            #
# Windows to quote pathnames and use            #
# double backslashes, e.g.:                     #
# "C:\\Program Files\\Open×××\\config\\foo.key" #
#                                               #
# Comments are preceded with '#' or ';'         #
#################################################
# Which local IP address should Open×××
# listen on? (optional)
;local a.b.c.d
# Which TCP/UDP port should Open××× listen on?
# If you want to run multiple Open××× instances
# on the same machine, use a different port
# number for each one.  You will need to
# open up this port on your firewall.
port 1194
# TCP or UDP server?
proto tcp
#proto udp
# "dev tun" will create a routed IP tunnel,
# "dev tap" will create an ethernet tunnel.
# Use "dev tap0" if you are ethernet bridging
# and have precreated a tap0 virtual interface
# and bridged it with your ethernet interface.
# If you want to control access policies
# over the ×××, you must create firewall
# rules for the the TUN/TAP interface.
# On non-Windows systems, you can give
# an explicit unit number, such as tun0.
# On Windows, use "dev-node" for this.
# On most systems, the ××× will not function
# unless you partially or fully disable
# the firewall for the TUN/TAP interface.
;dev tap
dev tun
# Windows needs the TAP-Win32 adapter name
# from the Network Connections panel if you
# have more than one.  On XP SP2 or higher,
# you may need to selectively disable the
# Windows firewall for the TAP adapter.
# Non-Windows systems usually don't need this.
;dev-node MyTap
# SSL/TLS root certificate (ca), certificate
# (cert), and private key (key).  Each client
# and the server must have their own cert and
# key file.  The server and all clients will
# use the same ca file.
#
# See the "easy-rsa" directory for a series
# of scripts for generating RSA certificates
# and private keys.  Remember to use
# a unique Common Name for the server
# and each of the client certificates.
#
# Any X509 key management system can be used.
# Open××× can also use a PKCS #12 formatted key file
# (see "pkcs12" directive in man page).
ca ca.crt
cert server.crt
key server.key  # This file should be kept secret
# Diffie hellman parameters.
# Generate your own with:
#   openssl dhparam -out dh2048.pem 2048
dh dh2048.pem
# Network topology
# Should be subnet (addressing via IP)
# unless Windows clients v2.0.9 and lower have to
# be supported (then net30, i.e. a /30 per client)
# Defaults to net30 (not recommended)
;topology subnet
# Configure server mode and supply a ××× subnet
# for Open××× to draw client addresses from.
# The server will take 10.8.0.1 for itself,
# the rest will be made available to clients.
# Each client will be able to reach the server
# on 10.8.0.1. Comment this line out if you are
# ethernet bridging. See the man page for more info.
server 10.10.10.0 255.255.255.0
# Maintain a record of client <-> virtual IP address
# associations in this file.  If Open××× goes down or
# is restarted, reconnecting clients can be assigned
# the same virtual IP address from the pool that was
# previously assigned.
ifconfig-pool-persist ipp.txt
# Configure server mode for ethernet bridging.
# You must first use your OS's bridging capability
# to bridge the TAP interface with the ethernet
# NIC interface.  Then you must manually set the
# IP/netmask on the bridge interface, here we
# assume 10.8.0.4/255.255.255.0.  Finally we
# must set aside an IP range in this subnet
# (start=10.8.0.50 end=10.8.0.100) to allocate
# to connecting clients.  Leave this line commented
# out unless you are ethernet bridging.
;server-bridge 10.8.0.4 255.255.255.0 10.8.0.50 10.8.0.100
# Configure server mode for ethernet bridging
# using a DHCP-proxy, where clients talk
# to the Open××× server-side DHCP server
# to receive their IP address allocation
# and DNS server addresses.  You must first use
# your OS's bridging capability to bridge the TAP
# interface with the ethernet NIC interface.
# Note: this mode only works on clients (such as
# Windows), where the client-side TAP adapter is
# bound to a DHCP client.
;server-bridge
# Push routes to the client to allow it
# to reach other private subnets behind
# the server.  Remember that these
# private subnets will also need
# to know to route the Open××× client
# address pool (10.8.0.0/255.255.255.0)
# back to the Open××× server.
push "route 192.168.5.0 255.255.255.0"
;push "route 192.168.20.0 255.255.255.0"
# To assign specific IP addresses to specific
# clients or if a connecting client has a private
# subnet behind it that should also have ××× access,
# use the subdirectory "ccd" for client-specific
# configuration files (see man page for more info).
# EXAMPLE: Suppose the client
# having the certificate common name "Thelonious"
# also has a small subnet behind his connecting
# machine, such as 192.168.40.128/255.255.255.248.
# First, uncomment out these lines:
;client-config-dir ccd
;route 192.168.40.128 255.255.255.248
# Then create a file ccd/Thelonious with this line:
#   iroute 192.168.40.128 255.255.255.248
# This will allow Thelonious' private subnet to
# access the ×××.  This example will only work
# if you are routing, not bridging, i.e. you are
# using "dev tun" and "server" directives.
# EXAMPLE: Suppose you want to give
# Thelonious a fixed ××× IP address of 10.9.0.1.
# First uncomment out these lines:
;client-config-dir ccd
;route 10.9.0.0 255.255.255.252
# Then add this line to ccd/Thelonious:
#   ifconfig-push 10.9.0.1 10.9.0.2
# Suppose that you want to enable different
# firewall access policies for different groups
# of clients.  There are two methods:
# (1) Run multiple Open××× daemons, one for each
#     group, and firewall the TUN/TAP interface
#     for each group/daemon appropriately.
# (2) (Advanced) Create a script to dynamically
#     modify the firewall in response to access
#     from different clients.  See man
#     page for more info on learn-address script.
;learn-address ./script
# If enabled, this directive will configure
# all clients to redirect their default
# network gateway through the ×××, causing
# all IP traffic such as web browsing and
# and DNS lookups to go through the ×××
# (The Open××× server machine may need to NAT
# or bridge the TUN/TAP interface to the internet
# in order for this to work properly).
push "redirect-gateway def1 bypass-dhcp"
# Certain Windows-specific network settings
# can be pushed to clients, such as DNS
# or WINS server addresses.  CAVEAT:
# http://open***.net/faq.html#dhcpcaveats
# The addresses below refer to the public
# DNS servers provided by opendns.com.
push "dhcp-option DNS 223.5.5.5"
push "dhcp-option DNS 223.6.6.6"
# Uncomment this directive to allow different
# clients to be able to "see" each other.
# By default, clients will only see the server.
# To force clients to only see the server, you
# will also need to appropriately firewall the
# server's TUN/TAP interface.
;client-to-client
# Uncomment this directive if multiple clients
# might connect with the same certificate/key
# files or common names.  This is recommended
# only for testing purposes.  For production use,
# each client should have its own certificate/key
# pair.
#
# IF YOU HAVE NOT GENERATED INDIVIDUAL
# CERTIFICATE/KEY PAIRS FOR EACH CLIENT,
# EACH HAVING ITS OWN UNIQUE "COMMON NAME",
# UNCOMMENT THIS LINE OUT.
;duplicate-cn
# The keepalive directive causes ping-like
# messages to be sent back and forth over
# the link so that each side knows when
# the other side has gone down.
# Ping every 10 seconds, assume that remote
# peer is down if no ping received during
# a 120 second time period.
keepalive 10 120
# For extra security beyond that provided
# by SSL/TLS, create an "HMAC firewall"
# to help block DoS attacks and UDP port flooding.
#
# Generate with:
#   open*** --genkey --secret ta.key
#
# The server and each client must have
# a copy of this key.
# The second parameter should be '0'
# on the server and '1' on the clients.
;tls-auth ta.key 0 # This file is secret
# Select a cryptographic cipher.
# This config item must be copied to
# the client config file as well.
# Note that 2.4 client/server will automatically
# negotiate AES-256-GCM in TLS mode.
# See also the ncp-cipher option in the manpage
cipher AES-256-CBC
# Enable compression on the ××× link and push the
# option to the client (2.4+ only, for earlier
# versions see below)
;compress lz4-v2
;push "compress lz4-v2"
# For compression compatible with older clients use comp-lzo
# If you enable it here, you must also
# enable it in the client config file.
;comp-lzo
# The maximum number of concurrently connected
# clients we want to allow.
max-clients 100
# It's a good idea to reduce the Open×××
# daemon's privileges after initialization.
#
# You can uncomment this out on
# non-Windows systems.
user nobody
group nobody
# The persist options will try to avoid
# accessing certain resources on restart
# that may no longer be accessible because
# of the privilege downgrade.
persist-key
persist-tun
# Output a short status file showing
# current connections, truncated
# and rewritten every minute.
status open***-status.log
# By default, log messages will go to the syslog (or
# on Windows, if running as a service, they will go to
# the "\Program Files\Open×××\log" directory).
# Use log or log-append to override this default.
# "log" will truncate the log file on Open××× startup,
# while "log-append" will append to it.  Use one
# or the other (but not both).
log         open***.log
;log-append  open***.log
# Set the appropriate level of log
# file verbosity.
#
# 0 is silent, except for fatal errors
# 4 is reasonable for general usage
# 5 and 6 can help to debug connection problems
# 9 is extremely verbose
verb 5
# Silence repeating messages.  At most 20
# sequential messages of the same message
# category will be output to the log.
;mute 20
# Notify the client that when the server restarts so it
# can automatically reconnect.
#explicit-exit-notify 1

默认内容比较多,所以我们过滤一下

cat /etc/open***/server.conf | grep "^[^#|^;]"
port 1194
proto tcp
dev tun
ca ca.crt
cert server.crt
key server.key  # This file should be kept secret
dh dh2048.pem
server 10.10.10.0 255.255.255.0
ifconfig-pool-persist ipp.txt
push "route 192.168.5.0 255.255.255.0"
push "dhcp-option DNS 223.5.5.5"
push "dhcp-option DNS 223.6.6.6"
keepalive 10 120
max-clients 100
user nobody
group nobody
persist-key
persist-tun
status open***-status.log
log         open***.log
verb 5

我们在修改前首先要需要将将原来默认的进行重命名一下作为备份。

mv /etc/open***/server.conf /etc/open***/server.conf.bak2

然后我们在/etc/open***目录下vi server.conf文件,然后将过滤的内容粘贴修改即可

vim server.conf
local 192.168.5.20    #监听地址
port 1194      #监听端口
proto tcp      #监听协议
dev tun      #采用路由隧道模式
ca ca.crt  #ca证书路径
cert server.crt    #服务器证书
key server.key    # This file should be kept secret 服务器密钥
dh dh2048.pem  #密钥交换协议文件
server 10.8.0.0 255.255.255.0        #给客户端分配地址池,注意:不能和×××服务器内网网段有相同
ifconfig-pool-persist ipp.txt
push "route 192.168.6.0 255.255.255.0"  #允许客户端访问内网 6.0 的网段。
push"dhcp-option DNS 223.5.5.5"              #dhcp分配dns
client-to-client    #客户端之间互相通信
keepalive 10 120  #存活时间,10秒ping一次,120 如未收到响应则视为断线
comp-lzo        #传输数据压缩
max-clients 100  #最多允许 100 客户端连接
user nobody        #用户
group nobody      #用户组
persist-key
persist-tun
status        /var/log/open***/open***-status.log
log        /var/log/open***/open***.log
verb 5

然后我们需要是使用用户和密码验证登陆,所以还需要添加以下语句

auth-user-pass-verify /etc/open***/checkpsw.sh via-env
client-cert-not-required
username-as-common-name

我们添加后

port 1194   #监听端口
proto tcp   #监听协议
dev tun     #采用隧道
ca ca.crt   #ca证书路劲
cert server.crt    #服务器证书路劲
key server.key  #服务器秘钥
dh dh2048.pem    #秘钥交换协议文件
server 10.10.10.0 255.255.255.0   #给客户端分配的地址,注意:不能和***服务器的内部地址相同
ifconfig-pool-persist ipp.txt    #访问记录
push "route 192.168.5.0 255.255.255.0"    #允许客户端访问的地址网段
#push "redirect-gateway def1 bypass-dhcp"
push "dhcp-option DNS 223.5.5.5"   #DHCP分配的DNS
push "dhcp-option DNS 223.6.6.6"
keepalive 10 120   #活动时间,10秒ping一次,120秒如果未收到响应视为断线
#cipher AES-256-CBC
max-clients 100   #允许最大连接数
#user nobody     #用户
#group nobody    #用户组
persist-key
persist-tun
status open***-status.log
log         open***.log
verb 5
client-cert-not-required
username-as-common-name
script-security 3
auth-user-pass-verify /etc/open***/checkpsw.sh via-env

第三步:新建用户和密码认证文件,psw-file(这里的文件就是server.conf那个文件,注意存放时,路径和配置文件时的一致)

cd /etc/open***/
vim psw-file
test123456 (前面是用户 后面是密码)

注:这里 psw-file的权限,尽量小点

chmod 400 psw-file
chmod +x checkpsw.sh

修改好后,我们重启open***服务

第四步:修改客户端配置文件:client.conf(或者client.o***)

注销掉这两行

#cert client1.crt
#key client1.key

再添加这一行,添加这行,就会提示输入用户名和密码

auth-user-pass

我们为了显示好看及好判断问题,所以我们需要把客户端的配置文件清空,然后编写有用的

client
dev tun
proto tcp
remote 192.168.5.20 1194
resolv-retry infinite
nobind
persist-key
persist-tun
ca ca.crt
# cert client.crt
#key client.key
#remote-cert-tls server
verb 5
auth-user-pass

保存会,我们单击open***客户端,然后连接,会提示输入账户及密码

最后我们可以查看log确认登陆情况

tail -f /etc/open***/open***.log

tail -f /etc/open***/open***-password.log

转载于:https://blog.51cto.com/gaowenlong/1886732

Centos7+Open***使用用户及密码验证登陆相关推荐

  1. Elasticsearch、Elasticsearch-head、Kibana 安全设置账号密码验证登陆

    Elasticsearch.Elasticsearch-head.Kibana 安全设置账号密码验证登陆 我的小站.Github.CSDN X-Pack 是 Elastic Stack 的一个扩展,提 ...

  2. centos7 创建新用户,使用ssh登陆,禁止root登陆,密码登陆

    1.先使用root用户登陆,创建新用,为新用户创建密码 useradd guest passwd guest 2.为用户分配sudo权限 gpasswd -a guest wheel //给予sudo ...

  3. Java连接数据库实现用户登录密码验证

    目录结构图: 1.在store_db数据库中创建一个t_user表; 在domain包中创建一个User的类: package com.xxf.domain;public class User {pr ...

  4. 随机验证码、用户登录密码验证、手机号加密案例

    String类案例 1.随机数案例 package zrzy.qrs.stringequals;import java.util.Random;/** *需求:获取一个随机5位的验证码,包含字母大小写 ...

  5. Linux学习笔记35——特定权限设置(比group、user更细的设置)、身份切换(su、sudo)、密码验证过程详解(PAM)、批量创建用户

    一.主机的细部权限规划:ACL 的使用 从第五章开始,我们就一直强调 Linux 的权限概念是非常重要的! 但是传统的权限仅有三种身份 ( owner, group, others) 搭配三种权限 ( ...

  6. Centos7.x 单用户模式修改root密码

    介绍: 之前使用的Centos6的单用户模式发现不适合Centos7使用,于是使用VMware Workstation记录Centos7的操作. 1.重启需要重置密码的虚机 2.看到此界面后,快速按& ...

  7. CentOS7之新建用户与SSH登陆

    登录云服务器 //选择一: 账号密码登录 ssh -q root@公用IP地址 然后输入密码(提示linux密码,没有长度****提示)//选择二:秘钥登录 ssh -i 公用秘钥文件路径 root@ ...

  8. 用户姓名保护python_Python操作LDAP,对用户进行认证(验证用户名以及密码)

    Python操作LDAP,对用户进行认证 1.环境 Python版本: 3.7.1 操作系统:windows 7 x64 第三方包:python-ldap 2.LDAP LDAP,它是基于X.500标 ...

  9. emqx配置mysql认证,emqx使用mysql完成用户密码验证和ACL鉴权

    emqx使用mysql完成用户密码验证和ACL鉴权 emqx使用mysql完成用户密码验证和ACL鉴权 摘要:前几篇博客介绍的是使用配置文件配置了ACL和客户端用户名密码配置实现生产环境下的安全登录和 ...

最新文章

  1. 一种准标准CSV格式的介绍和分析以及解析算法
  2. ELK(+Redis)+LogAnalyzer解决企业日志问题
  3. C# 获取当前路径方法
  4. Android 实用工具Hierarchy Viewer实战
  5. c java http_[C] 类似于HttpClient的C语言实现Http POST功能如何实现?
  6. tomcat拒绝访问是为什么_Tomcat中的connectTimeout和慢攻击
  7. 在sql server里,日期字段按天数进行group by查询的方法
  8. 微服务太分散?使用Fundebug集中式bug监控
  9. 【堪萨斯州立大学】电子和计算机工程系智能能源研究室、硬件安全实验室招募博士,提供多个全额奖学金机会...
  10. CCS实例,网页栏目
  11. 李峋同款的C语言动态爱心代码(终于不是html的啦)
  12. matlab求两向量夹角_高考数学一轮复习,利用空间向量求夹角和距离,各考点聚焦突破...
  13. 正样本/反(负)样本/易区分样本/难区分样本
  14. 物联网--ESP32开发笔记(2) domoticz mqtt的一些坑的记录
  15. 收集的JS常用正则表达式等(转载)
  16. 盛天海科技:拼多多团长这样来做
  17. 数学中说的线性关系线性是什么意思?
  18. 案例分享-21款奔驰S450L升级原厂夜色饰条套件
  19. 进入知识储备期的通知
  20. 知否:高增长时代已过,汽车互联网玩家如何开拓更多增量?

热门文章

  1. VUE引入Echarts 打包文件过大——解决方法1:按需引入
  2. UG NX 12 曲面
  3. rfcn 共享_LTE无线频谱划分及RFCN
  4. 《经典食人花》windows经典桌面游戏食人花(吃花)登陆iOS,Android啦
  5. 什么是控标?常见的控标手段有哪些?
  6. 以太坊源码解读(1)以太坊核心概念
  7. 记录一次C# 使用FFmpeg提取音频文件
  8. 深入浅出pytorch笔记——第三章,第四章
  9. 同城预约洗车服务小程序同城洗车上门洗车门店优惠券会员预约洗车程序
  10. Linux- 系统随你玩之--微服务应用出现极少概率会时断时续,它抽风了吗?