{"id":552,"date":"2019-09-27T15:56:20","date_gmt":"2019-09-27T07:56:20","guid":{"rendered":"https:\/\/www.linuxdevops.cn\/?p=552"},"modified":"2022-06-24T11:09:35","modified_gmt":"2022-06-24T03:09:35","slug":"osxzhmmdl","status":"publish","type":"post","link":"https:\/\/www.linuxdevops.cn\/2019\/09\/osxzhmmdl\/","title":{"rendered":"OpenVPN\u5b9e\u73b0\u8d26\u53f7\u5bc6\u7801\u767b\u5f55(\u65e7\u7248)"},"content":{"rendered":"\n
\u4e0a\u4e00\u7bc7\u6587\u7ae0\u5df2\u7ecf\u6210\u529f\u7684\u642d\u5efa\u597d OpenVPN \u4e86\uff0c\u5ba2\u6237\u7aef\u76f4\u63a5\u4f7f\u7528\u8bc1\u4e66\u5c31\u53ef\u4ee5\u8fde\u63a5\u4e86\uff0c\u4f46\u662f\u591a\u4e2a\u4eba\u4f7f\u7528\u7684\u8bdd\uff0c\u5efa\u8bae\u8fd8\u662f\u6539\u4e3a\u8d26\u53f7+\u5bc6\u7801\u65b9\u5f0f\u7684\uff0c \u89e3\u51b3\u4e86\u8bc1\u4e66\u8ba4\u8bc1\u7684\u4e00\u8bc1\u4e66\u4e00\u5ba2\u6237\u7aef\u7684\u9650\u5236\u3002 <\/p>\n\n\n
cat \/etc\/openvpn\/checkpsw.sh <\/p>\n\n\n
#!\/bin\/sh\n###########################################################\n# checkpsw.sh (C) 2004 Mathias Sundman <mathias@openvpn.se>\n#\n# This script will authenticate OpenVPN users against\n# a plain text file. The passfile should simply contain\n# one row per user with the username first followed by\n# one or more space(s) or tab(s) and then the password.\n\nPASSFILE=\"\/etc\/openvpn\/psw-file\"\nLOG_FILE=\"\/etc\/openvpn\/openvpn-password.log\"\nTIME_STAMP=date "+%Y-%m-%d %T"<\/code>\n\n###########################################################\n\nif [ ! -r \"${PASSFILE}\" ]; then\n echo \"${TIME_STAMP}: Could not open password file \\\"${PASSFILE}\\\" for reading.\" >> ${LOG_FILE}\n exit 1\nfi\n\nCORRECT_PASSWORD=awk '!\/^;\/&&!\/^#\/&&$1=="'${username}'"{print $2;exit}' ${PASSFILE}<\/code>\n\nif [ \"${CORRECT_PASSWORD}\" = \"\" ]; then \n echo \"${TIME_STAMP}: User does not exist: username=\\\"${username}\\\", password=\\\"${password}\\\".\" >> ${LOG_FILE}\n exit 1\nfi\n\nif [ \"${password}\" = \"${CORRECT_PASSWORD}\" ]; then \n echo \"${TIME_STAMP}: Successful authentication: username=\\\"${username}\\\".\" >> ${LOG_FILE}\n exit 0\nfi\n\necho \"${TIME_STAMP}: Incorrect password: username=\\\"${username}\\\", password=\\\"${password}\\\".\" >> ${LOG_FILE}\nexit 1\n\n<\/pre>\n\n\n\u7ed9\u4e88\u811a\u672c\u6267\u884c\u6743\u9650\uff1a<\/p>\n\n\n
chmod 755 \/etc\/openvpn\/checkpsw.sh<\/code><\/pre>\n\n\n2.\u914d\u7f6e\u7528\u6237\u5bc6\u7801\u6587\u4ef6<\/h4>\n\n\n
\u914d\u7f6e \u8d26\u53f7\/\u5bc6\u7801\uff0c\u65b0\u589e\u8d26\u53f7\/\u5bc6\u7801\u589e\u52a0\u5230\u8fd9\u91cc\u5373\u53ef \uff0c\u4e00\u884c\u4e00\u4e2a\u8d26\u53f7\uff0c\u5bc6\u7801\u7528\u7a7a\u683c\u9694\u5f00\uff1a <\/p>\n\n\n
[root@localhost ~]# cat \/etc\/openvpn\/psw-file\nuser1 passwd1\nuser2 passwd2<\/code><\/pre>\n\n\n3.\u4fee\u6539\u670d\u52a1\u7aef\u914d\u7f6e\u6587\u4ef6<\/h4>\n\n\n\u5728server.conf\u672b\u5c3e\u6dfb\u52a0\u5982\u4e0b\u51e0\u884c\u4fe1\u606f\uff1a\nscript-security 3 \nauth-user-pass-verify \/etc\/openvpn\/checkpsw.sh via-env #\u6307\u5b9a\u7528\u6237\u8ba4\u8bc1\u811a\u672c\nusername-as-common-name\nverify-client-cert none\nclient-cert-not-required #\u4ee3\u8868\u53ea\u4f7f\u7528\u7528\u6237\u540d\u5bc6\u7801\u65b9\u5f0f\u9a8c\u8bc1\u767b\u5f55\uff0c\u5982\u679c\u4e0d\u52a0\uff0c\u5219\u4ee3\u8868\u9700\u8981\u8bc1\u4e66\u548c\u7528\u6237\u540d\u5bc6\u7801\u53cc\u91cd\u9a8c\u8bc1\u767b\u5f55\uff01\nclient-config-dir \/etc\/openvpn\/client #\u56fa\u5b9a\u5ba2\u6237\u7aefIp<\/code><\/pre>\n\n\n 4.\u914d\u7f6e\u5ba2\u6237\u7aef\u56fa\u5b9aIP <\/h4>\n\n\n
mkdir \/etc\/openvpn\/client #\u65b0\u5efa\u76ee\u5f55 <\/p>\n\n\n
\u914d\u7f6e\u5177\u4f53\u7528\u6237\u7684IP<\/p>\n\n\n
cat user1 #user1 \u6587\u4ef6\u540d \u5bf9\u5e94pws-file\u6587\u4ef6\u91cc\u9762\u8bbe\u7f6e\u7684\u7528\u6237\u540d\nifconfig-push 172.16.0.56 172.16.0.57<\/code><\/pre>\n\n\n\u5ba2\u6237\u7aef\u56fa\u5b9aIP\u9009\u914d\uff0c\u6839\u636e\u4f60\u7684\u9700\u6c42\u6765\u3002<\/p><\/blockquote>\n\n\n
5.\u91cd\u542f\u670d\u52a1<\/h4>\n\n\n
systemctl restart openvpn<\/p>\n\n\n
\n\n\u5ba2\u6237\u7aef\u914d\u7f6e\u6587\u4ef6\n\n<\/h2>\n\n\n
\u6ce8\u91ca\u6389cert\u548ckey\uff08\u5ba2\u6237\u7aef\u4e0d\u9700\u8981crt\u548ckey\u6587\u4ef6\uff0c\u4f46\u662f\u9700\u8981\u670d\u52a1\u5668\u7684CA\u8bc1\u4e66,ta.key\uff09<\/strong>
\uff1bcert eva.crt<\/strong>
\uff1bkey eva.key<\/strong>
\u6dfb\u52a0\u5982\u4e0b\u5185\u5bb9:<\/strong>
auth-user-pass<\/strong><\/p>\n\n\n