OpenVPN 加上使用憑證搭配不需 Unix 帳戶的 Google Authenticator
網路上 OpenVPN 搭配 Google Authenticator 的文章有一些,寫的大多都沒問題。
但本人的環境是直接使用憑證認證。現在希望加上 Google Authenticator 進行認證。可是龜毛如我又不希望在我的 Ubuntu 上替每個人開個帳號(如果你有看過其他教學文章,幾乎使用 Google Authenticator 都是要使用每個人的帳戶去執行並產生認證碼)
其實 Google Authenticator 的程式都有想到,只是設定沒人特別教過。如果仔細看 README 就可以知道。這裡簡單說明如下
設定 pam.d/openvpn 時(我假設你是複製 common-account 設定過來的)一般最後一行就是加上
auth required pam_google_authenticator.so
這樣可以強迫啟用 google authenticator。而如果神祕的就是改用下面這行
auth required pam_google_authenticator.so secret=/etc/openvpn/google_authenticator/${USER}_google_authenticator user=gauser
意思是讀取使用者的 secret 檔不是讀取各自 home 目錄的檔案。而是改用/etc/openvpn/google_authenticator/ 下 XXXX_google_authenticator 的檔案(XXXX 是指用戶名稱)。因為這個檔案有權限限制(必須是 600)。所以後面又必須加上 user=gauser 這樣一串文字,意思是統一使用 gauser 這個 Unix 帳戶來讀取設定檔。否則他會試著找 XXXX 這個帳戶,結果找不到就無法登入。
當然因此你必須備好
/etc/openvpn/google_authenticator/ 目錄
gauser 這個 Unix 帳戶
之後要產生 secret 檔時,使用 google-authenticator -s /etc/openvpn/google_authenticator/XXXX_google_authenticator 來產生
概念大致上是這樣。如果本來給使用者的 OpenVPN 設定是指需要憑證且不需帳密就可登入的。現在可能原本 OpenVPN 的設定檔也得改,最前面得加上一行 auth-user-pass 。這樣才能強迫跳出輸入帳號密碼的視窗。

















