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***服務器
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章