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}" ]; 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


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


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


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

Centos配置登录提示信息 centos7用户登录_Centos配置登录提示信息

保存退出,然后我们需要修改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



Centos配置登录提示信息 centos7用户登录_Centos配置登录提示信息_02

然后我们在/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



Centos配置登录提示信息 centos7用户登录_数据库_03

我们添加后



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



Centos配置登录提示信息 centos7用户登录_运维_04

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



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



Centos配置登录提示信息 centos7用户登录_Centos配置登录提示信息_05

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



chmod 400 psw-file chmod +x checkpsw.sh



Centos配置登录提示信息 centos7用户登录_运维_06

Centos配置登录提示信息 centos7用户登录_Centos配置登录提示信息_07

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

Centos配置登录提示信息 centos7用户登录_Centos配置登录提示信息_08

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

注销掉这两行



#cert client1.crt
#key client1.key



Centos配置登录提示信息 centos7用户登录_运维_09

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



auth-user-pass



Centos配置登录提示信息 centos7用户登录_运维_10

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



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



Centos配置登录提示信息 centos7用户登录_Centos配置登录提示信息_11

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

Centos配置登录提示信息 centos7用户登录_数据库_12

Centos配置登录提示信息 centos7用户登录_Centos配置登录提示信息_13

Centos配置登录提示信息 centos7用户登录_数据库_14

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


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

Centos配置登录提示信息 centos7用户登录_Centos配置登录提示信息_15



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



Centos配置登录提示信息 centos7用户登录_网络_16


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