<?xml version="1.0" encoding="UTF-8" ?><oembed><version>1.0</version><provider_name>Jui-Nan Lin&#039;s Blog</provider_name><provider_url>https://jnlin.org</provider_url><author_name>jnlin</author_name><author_url>https://jnlin.org/author/jnlin/</author_url><title>security/pam_google_authenticator: Two Factor Authentication PAM Module</title><html>&lt;p&gt;&lt;a href=&quot;http://www.freshports.org/security/pam_google_authenticator&quot;&gt;security/pam_google_authenticator&lt;/a&gt; 是 Google 推出的 Open Source PAM Module，提供 &lt;a href=&quot;http://tools.ietf.org/html/rfc4226&quot;&gt;RFC 4226&lt;/a&gt; (HOTP: An HMAC-Based One-Time Password Algorithm) 的 OTP 功能。&lt;/p&gt;  &lt;p&gt;只要使用 Android 手機（未來會支援iOS裝置），安裝 Google&#160; 提供的 App，開啟並設定 pam_google_authenticator，之後的 ssh 連線就可以使用 OTP 登入。&lt;/p&gt;  &lt;p&gt;Linux 上的安裝方法可以看 &lt;a href=&quot;http://twitter.com/gasol&quot;&gt;@gasol&lt;/a&gt; 寫的&lt;a href=&quot;http://blog.gasol.tw/2011/05/google-authenticator.html&quot;&gt;替主機上第二道鎖 - Google Authenticator&lt;/a&gt;，這裡介紹的是 FreeBSD 上的安裝方法：&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;先安裝 security/pam_google_authenticator &lt;/li&gt;    &lt;li&gt;執行 google-authenticator ，設定 secret key。螢幕上會出現一個 &lt;a href=&quot;http://en.wikipedia.org/wiki/QR_code&quot;&gt;QR Code&lt;/a&gt;，用手機 App 掃描之後就會把 secret key 存到手機內。接著按照螢幕上指示把 secret key 存到 ~/.google_authenticator 裡。記得要 chmod 600。 &lt;/li&gt;    &lt;li&gt;設定 /etc/pam.d/sshd，在 auth pam_unix 下面增加一行： &lt;/li&gt; &lt;/ol&gt;  &lt;blockquote&gt;   &lt;p&gt;auth required /usr/local/lib/pam_google_authenticator.s&lt;font color=&quot;#444444&quot;&gt;o&lt;/font&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;這樣就生效了。要注意的是，這不會影響使用 Public/Private Key Pair 登入的使用者。另外，PAM設定完成之後，如果沒有設定 secret key 的使用者，就不能用帳號密碼登入了。&lt;/p&gt;  &lt;p&gt;測試前記得請留下一個連線的 terminal，避免設錯導致人得跑到 console 前去處理。&lt;/p&gt;</html><type>rich</type></oembed>