建置使用帳號及密碼認證的 OpenVPN Server – 2

試用了 OpenVPN AS 之後,發現其實也可以考慮使用 Unix-Like 本地端的帳號來進行認證。
參考網站:
Setup PAM authentication with OpenVPN’s auth-pam module – Linux Sysadmin Tutorials

1. 建立帳號及密碼
# useradd test -s /bin/false
# passwd test

2. 建立 /etc/pam.d/openvpn
# cat /etc/pam.d/openvpn
auth    required        pam_unix.so    shadow    nodelay
auth    requisite       pam_succeed_if.so uid >= 500 quiet
auth    required        pam_tally2.so deny=4 even_deny_root unlock_time=1200
account required        pam_unix.so[@more@]3. 安裝所需套件
# apt-get install libsasl2-2 sasl2-bin

4. 修改 OpenVPN 設定檔 /etc/openvpn/server.conf
加入下面幾行
client-cert-not-required
username-as-common-name
plugin /usr/lib/openvpn/openvpn-plugin-auth-pam.so openvpn

openvpn-plugin-auth-pam.so 檔案的位置要確認

5. 檢查 OpenVPN 設定檔是否正確
# openvpn –config /etc/openvpn/server.conf

6. 重新啟動 OpenVPN Server,並檢查是否有正常啟動
# systemctl restart openvpn@server.service;systemctl status openvpn@server.service

7. 修改 saslauthd 設定檔 /etc/default/saslauthd
# sed -i ‘s/START=no/START=yes/’ /etc/default/saslauthd

8. 建議重新啟動系統
# sync;sync;sync;reboot

9. 檢查帳號密碼是否能正常使用
# testsaslauthd -u test -p 123456 -s openvpn
0: OK “Success.”
如果出現以上的訊息,代表正常

connect() : No such file or directory
0:
如果出現上面訊息,代表 saslauthd 沒有啟動,請做第 7 步驟

0: NO “authentication failed”
如果出現上面訊息,代表認證失敗,可能要查看一下 /var/log/auth.log 中的訊息

10. 在 OpenVPN Cleint 端的設定檔中,加入下面這一行
auth-user-pass