{"id":301,"date":"2012-07-24T21:37:42","date_gmt":"2012-07-24T13:37:42","guid":{"rendered":"http:\/\/www.ipcpu.com\/?p=301"},"modified":"2012-07-24T21:37:42","modified_gmt":"2012-07-24T13:37:42","slug":"google-auth-sshd","status":"publish","type":"post","link":"https:\/\/c.ipcpu.com\/2012\/07\/google-auth-sshd\/","title":{"rendered":"\u4f7f\u7528Google Authenticator\u5bf9SSH\u8fdb\u884c\u9a8c\u8bc1"},"content":{"rendered":"

Google Authenticator\u662f\u4e00\u4e2a\u4e00\u6b21\u6027\u5bc6\u7801\u751f\u6210\u5668\uff0c\u652f\u6301HOTP\uff08HMAC-based one time password\uff0c\u7531RFC 4226\u5b9a\u4e49\uff09\u548cTOTP\uff08Time-based one time password\uff09\u3002<\/p>\n

Google Authenticator\u5728Android\u3001iOS\u548cBlackberry\u4e0a\u9762\u90fd\u6709\u539f\u751f\u7684\u5ba2\u6237\u7aef\uff0c\u540c\u65f6\u8fd8\u6709\u4eba\u5f00\u53d1\u4e86j2me\u7248\u672c\u7684\u5ba2\u6237\u7aef\uff0c\u56e0\u800c\u57fa\u672c\u4e0a\u5e02\u9762\u4e0a\u7684\u6240\u6709\u624b\u673a\/\u79fb\u52a8\u8bbe\u5907\u90fd\u53ef\u4ee5\u4f7f\u7528\u3002<\/p>\n

Google Authenticator\u540c\u65f6\u8fd8\u63d0\u4f9b\u4e86PAM\u6a21\u5757\uff0c\u56e0\u800c\u4e5f\u53ef\u7528\u4e8eUnix\/Linux\u7684\u9a8c\u8bc1\u5de5\u4f5c\u3002<\/p>\n

\u6211\u4eec\u5c31\u662f\u7528GA\u7684pam\u6a21\u5757\u5bf9ssh\u8fdb\u884c\u9a8c\u8bc1\u3002<\/p>\n

\u6211\u4eec\u8981\u5b9e\u73b0\u7684\u76ee\u7684\uff1a<\/strong><\/p>\n

\u767b\u9646Linux\u670d\u52a1\u5668\u65f6\uff0c\u5148\u63d0\u793a\u8f93\u5165TOTP\u4e00\u6b21\u6027\u5bc6\u7801\uff0c\u7136\u540e\u518d\u8f93\u5165\u5bc6\u7801\uff0c\u4e24\u4e2a\u90fd\u6b63\u786e\u540e\uff0c\u65b9\u53ef\u4ee5\u767b\u9646\u7cfb\u7edf\u3002TOTP\u5bc6\u7801\u53ef\u4ee5\u4f7f\u7528\u5b89\u5353\u624b\u673a\u7684Google Authenticator\u83b7\u5f97\u3002<\/p>\n

\u4e00\u3001Linux\u670d\u52a1\u5668\u7aef\u7684\u914d\u7f6e<\/strong><\/p>\n

1.\u9996\u5148\u53bbhttp:\/\/code.google.com\/p\/google-authenticator\/<\/a>\u4e0b\u8f7dGA\u7684pam\u5305<\/p>\n

2.\u5b89\u88c5<\/p>\n

cd libpam-google-authenticator-1.0<\/span><\/p>\n

make<\/span><\/p>\n

cp pam_google_authenticator.so<\/span>\u00a0\u00a0\/lib\/security\/<\/span>
\n\u4fee\u6539\/etc\/ssh\/sshd_config\uff0c\u4fdd\u8bc1\u6709\u4e0b\u9762\u4e24\u884c<\/p>\n

ChallengeResponseAuthentication yes<\/span><\/p>\n

UsePAM yes<\/span>
\n\u4fee\u6539\/etc\/pam.d\/sshd\uff0c\u5728\u7b2c\u4e00\u884c\u6dfb\u52a0<\/span>
\nauth<\/span>\u00a0 \u00a0 \u00a0\u00a0\u00a0required<\/span>\u00a0 \u00a0\u00a0\u00a0pam_google_authenticator.so<\/span><\/p>\n

\n

3.\u6267\u884c\u5b89\u88c5\u76ee\u5f55\u5185\u751f\u6210\u7684google-authenticator\u6309\u7167\u63d0\u793a\u8bf4\u5982\u5373\u53ef\u3002\u4e00\u822c\u90fd\u9009\u62e9yes\u3002<\/p>\n

\u8fd9\u65f6google-authenticator\u4f1a\u5728\u5f53\u524d\u7528\u6237\u6839\u76ee\u5f55\u4e0b\u751f\u6210\u4e00\u4e2a.google_authenticator\u6587\u4ef6\u3002<\/p>\n

\u8fd9\u91cc\u9762\u8bb0\u5f55\u4e86GA\u8ba4\u8bc1\u4f7f\u7528\u7684\u5bc6\u94a5\u3002<\/p>\n

\n

[root@s0 libpam-google-authenticator-1.0]# .\/google-authenticator<\/span><\/p>\n

Do you want authentication tokens to be time-based (y\/n) y<\/span><\/p>\n

https:\/\/www.google.com\/chart?chs=200\u00d7200&chld=M|0&cht=qr&chl=otpauth:\/\/totp\/root@s0.ipcpu.com%3Fsecret%3D3YTC5HUNKX6DKQIJ<\/span><\/p>\n

Your new secret key is: 3YTC5HUNKX6DKQIJ<\/span><\/p>\n

Your verification code is 749235<\/span><\/p>\n

Your emergency scratch codes are:<\/span><\/p>\n

15880449<\/span><\/p>\n

89566424<\/span><\/p>\n

44741806<\/span><\/p>\n

69879901<\/span><\/p>\n

87471700<\/span><\/p>\n

\n

Do you want me to update your \u201c\/root\/.google_authenticator\u201d file (y\/n) y<\/span><\/p>\n

Do you want to disallow multiple uses of the same authentication<\/span><\/p>\n

token? This restricts you to one login about every 30s, but it increases<\/span><\/p>\n

your chances to notice or even prevent man-in-the-middle attacks (y\/n) y<\/span><\/p>\n

By default, tokens are good for 30 seconds and in order to compensate for<\/span><\/p>\n

possible time-skew between the client and the server, we allow an extra<\/span><\/p>\n

token before and after the current time. If you experience problems with poor<\/span><\/p>\n

time synchronization, you can increase the window from its default<\/span><\/p>\n

size of 1:30min to about 4min. Do you want to do so (y\/n) y<\/span><\/p>\n

If the computer that you are logging into isn\u2019t hardened against brute-force<\/span><\/p>\n

login attempts, you can enable rate-limiting for the authentication module.<\/span><\/p>\n

By default, this limits attackers to no more than 3 login attempts every 30s.<\/span><\/p>\n

Do you want to enable rate-limiting (y\/n) y<\/span><\/p>\n

GA\u540c\u65f6\u63d0\u4f9b\u4e86\u4e00\u7ec4\u7d27\u6025\u5bc6\u7801\uff0c\u5728\u6ca1\u6709Google Authenticator\u5ba2\u6237\u7aef\u662f\u53ef\u4ee5\u4f7f\u7528\uff0c\u4f46\u662f\u6bcf\u4e2a\u7d27\u6025\u5bc6\u7801\u53ea\u80fd\u4f7f\u7528\u4e00\u6b21\u3002<\/p>\n

\u7136\u540e\u6211\u4eec\u91cd\u65b0\u542f\u52a8SSHD\uff0c\u670d\u52a1\u5668\u7aef\u7684\u8bbe\u7f6e\u5c31\u5b8c\u6210\u4e86\u3002<\/p>\n

\u4e8c\u3001\u624b\u673a\u5ba2\u6237\u7aef\u7684\u8bbe\u7f6e<\/strong><\/p>\n

1.\u6211\u4eec\u5c06\u670d\u52a1\u5668\u4e0a\u751f\u6210\u5bc6\u94a5\u7684\u94fe\u63a5\uff0c\u590d\u5236\u5230\u6d4f\u89c8\u5668\uff0c\u6253\u5f00\u4e4b\u540e\u4f1a\u663e\u793a\u4e00\u4e2aQR\u7801\u3002<\/p>\n

https:\/\/www.google.com\/chart?chs=200\u00d7200&chld=M|0&cht=qr&chl=otpauth:\/\/totp\/root@s0.ipcpu.com%3Fsecret%3D3YTC5HUNKX6DKQIJ<\/p>\n

2.\u5728\u5b89\u5353\u624b\u673a\u4e0a\u5b89\u88c5\u201cGoogle Authenticator\u201d \u53ef\u4ee5\u5728\u5b89\u5353\u81ea\u5e26\u7684\u7535\u5b50\u5e02\u573a\uff08\u73b0\u5df2\u6539\u540d\u4e3aGoogle Play\uff09\u4e0a\u627e\u5230\uff0c\u8fd9\u4e2a\u8f6f\u4ef6\u8fd8\u4f1a\u4f9d\u8d56\u6761\u5f62\u7801\u626b\u63cf\u5668\uff0c\u6253\u5f00Google Authenticator\u65f6\u4f1a\u81ea\u52a8\u63d0\u793a\u4e0b\u8f7d\u3002<\/p>\n

3.\u4f7f\u7528Google Authenticator\u626b\u63cf\u7b2c\u4e00\u6b65\u7684QR\u7801\u5373\u53ef\u3002\u8fd9\u6837\u6211\u4eec\u7684Google Authenticator\u4e0a\u4f1a\u6709\u4e00\u4e2a\u6bcf\u969430s\u53d8\u5316\u4e00\u6b21\u76846\u4f4d\u6570\u5b57\u3002\u5982\u56fe\u6240\u793a\uff1a<\/p>\n

\"goo01\"<\/a><\/p>\n

\u4e09\u3001SecureCRT\u767b\u5f55\u9a8c\u8bc1<\/strong><\/p>\n

\n

1.\u5c06SecureCRT\u7684\u8ba4\u8bc1\u65b9\u5f0f\u91cc\u9762\u7684keyboard Interactive\u63d0\u5230Password\u4e4b\u524d\u3002<\/p>\n

2.\u767b\u9646\u670d\u52a1\u5668\uff0c\u6211\u4eec\u4f1a\u5148\u6536\u5230Google Authenticator\u63d0\u793a\u7684\u8f93\u5165Verification code:\u6211\u4eec\u6309\u7167\u624b\u673a\u5f53\u524d\u663e\u793a\u7684\u6570\u5b57\u8f93\u5165\uff0c\u7136\u540e\u8f93\u5165\u5bc6\u7801\uff0c\u5c31\u53ef\u4ee5\u767b\u5f55\u670d\u52a1\u5668\u4e86\u3002<\/p>\n

\u00a0\"goo02\"<\/a><\/p>\n

\u56db\u3001\u5176\u4ed6\u6ce8\u610f\u4e8b\u9879<\/strong><\/p>\n

\n

1. Google Authenticator\u5bf9SSH\u9a8c\u8bc1\u548c\u4f7f\u7528\u5546\u7528\u7684OTP\u7cfb\u7edf\u6709\u5982\u4e0b\u533a\u522b\uff1a<\/p>\n

\u5546\u7528OTP\u7cfb\u7edf\u4e00\u822c\u662fC\/S\u7f51\u7edc\u7248\u65b9\u5f0f\uff0c\u6709\u4e00\u4e2a\u7edf\u4e00\u7684AuthenticationServer\uff0c\u4e3a\u4e86\u4fdd\u8bc1\u9ad8\u53ef\u7528\u4e00\u822c\u4f1a\u6709\u4e00\u4e3b\u4e00\u5907\u4e24\u53f0\u670d\u52a1\u5668\u3002Google Authenticator\u662f\u5355\u673a\u7248\u7684\u9a8c\u8bc1\u65b9\u5f0f\u3002<\/p>\n

2. Google Authenticator\u662f\u4e00\u4e2a\u57fa\u4e8e\u65f6\u95f4\u7684\u4ea7\u751f\u9a8c\u8bc1\u7801\u7684\u7a0b\u5e8f\uff0c\u56e0\u6b64\u4e0d\u7ba1\u662f\u670d\u52a1\u5668\u7aef\u8fd8\u662f\u624b\u673a\u5ba2\u6237\u7aef\uff0c\u5bf9\u65f6\u95f4\u7684\u8981\u6c42\u90fd\u662f\u975e\u5e38\u4e25\u683c\u3002\u8981\u65f6\u523b\u4fdd\u8bc1\u4e0eNTP\u670d\u52a1\u5668\u540c\u6b65\u3002<\/p>\n

3. Google Authenticator\u548c\u6761\u5f62\u7801\u626b\u63cf\u5668\u9ed8\u8ba4\u662f\u4e0d\u4f1a\u4ea7\u751f\u4efb\u4f55GPRS\u548cWIFI\u6d41\u91cf\u7684\u3002<\/p>\n

4. Google Authenticator\u662f\u4e00\u79cd\u9a8c\u8bc1\u7684\u65b9\u5f0f\uff0c\u53ef\u4ee5\u6269\u5c55\u5230\u5176\u4ed6\u7684\u5730\u65b9\uff0c\u4f8b\u5982wordpress\u7684\u7ba1\u7406\u5458\u767b\u9646\u7b49\u7b49\u3002\u6211\u8fd9\u91cc\u53ef\u4ee5\u63d0\u4f9b\u4e00\u4e2aPHP\u9a8c\u8bc1Google Authenticator\u7b97\u6cd5\u7684\u94fe\u63a5\uff1a<\/p>\n

http:\/\/www.idontplaydarts.com\/2011\/07\/google-totp-two-factor-authentication-for-php\/<\/a><\/p>\n

5. \u5982\u679c\u4e0d\u9700\u8981\u7528\u6237\u767b\u5f55\u65f6\u8f93\u5165OTP\u5bc6\u7801\uff0c\u800c\u662f\u5728\u7528\u6237su\u5230root\u65f6\u8981\u6c42\u8f93\u5165\uff0c\u53ef\u4ee5\u628apam\u8ba4\u8bc1\u8bed\u53e5\u52a0\u5165\u5230\/etc\/pam.d\/su\u5f53\u4e2d\u3002<\/p>\n

6. \u5f53\u670d\u52a1\u5668\u542f\u7528\u4e86pam\u8ba4\u8bc1\u4e4b\u540e\uff0c\u6240\u6709\u7684\u7528\u6237\u90fd\u662f\u8981\u6c42\u8f93\u5165TOTP\u5bc6\u7801\uff0c\u6240\u4ee5\u9700\u8981\u6bcf\u4e2a\u7528\u6237\u90fd\u5728\u81ea\u5df1\u7684\u76ee\u5f55\u4e0b\u751f\u6210\u4e00\u4e2a.google_authenticator\u6587\u4ef6\u3002<\/p>\n

7. WordPress\u4e2d\u7684Google Authenticator\u5b58\u5728\u5982\u4e0b\u7279\u70b9\uff1a<\/p>\n

\u8ba4\u8bc1\u662f\u57fa\u4e8e\u5355\u4e2a\u7528\u6237\u7684\uff0c\u53ea\u6709\u7528\u6237\u6fc0\u6d3bGoogle Authenticator\uff0c\u624d\u53ef\u4ee5\u4f7f\u7528\u3002\u7528\u6237\u4e0d\u6fc0\u6d3b\u65f6\uff0cGoogle Authenticator\u4e0d\u9700\u8981\u8f93\u5165\u5c31\u53ef\u4ee5\u901a\u8fc7\u9a8c\u8bc1\u3002\u53e6\u5916\u8fd9\u4e2a\u63d2\u4ef6\u6ca1\u6709\u63d0\u4f9b\u5b89\u5168\u5bc6\u7801\uff0c\u9632\u6b62\u624b\u673a\u4e0d\u5728\u8eab\u8fb9\u6216\u8005\u670d\u52a1\u5668\u65f6\u95f4\u4e0d\u51c6\u786e\u65f6\u767b\u9646\u4f7f\u7528\u3002<\/p>\n

\u8f6c\u8f7d\u8bf7\u6ce8\u660e\uff1aIPCPU-\u7f51\u7edc\u4e4b\u8def<\/a> » \u4f7f\u7528Google Authenticator\u5bf9SSH\u8fdb\u884c\u9a8c\u8bc1<\/a><\/p>","protected":false},"excerpt":{"rendered":"

Google Authenticator\u662f\u4e00\u4e2a\u4e00\u6b21\u6027\u5bc6\u7801\u751f\u6210\u5668\uff0c\u652f\u6301HOTP\uff08HMAC-based one time password\uff0c\u7531RFC 4226\u5b9a\u4e49\uff09\u548cTOTP\uff08Time-based one time password\uff09\u3002 Google Authenticator\u5728Android\u3001iOS\u548cBlackberry\u4e0a\u9762\u90fd\u6709\u539f\u751f\u7684\u5ba2\u6237\u7aef\uff0c\u540c\u65f6\u8fd8\u6709\u4eba\u5f00\u53d1\u4e86j2me\u7248\u672c\u7684\u5ba2\u6237\u7aef\uff0c\u56e0\u800c\u57fa\u672c\u4e0a\u5e02\u9762\u4e0a\u7684\u6240\u6709\u624b\u673a\/\u79fb\u52a8\u8bbe\u5907\u90fd\u53ef\u4ee5\u4f7f\u7528\u3002 Google Authenticator\u540c\u65f6\u8fd8\u63d0\u4f9b\u4e86PAM\u6a21\u5757\uff0c\u56e0\u800c\u4e5f\u53ef\u7528\u4e8eUnix\/Linux\u7684\u9a8c\u8bc1\u5de5\u4f5c\u3002 \u6211\u4eec\u5c31\u662f\u7528GA\u7684pam\u6a21\u5757\u5bf9ssh\u8fdb\u884c\u9a8c\u8bc1\u3002 \u6211\u4eec\u8981\u5b9e\u73b0\u7684\u76ee\u7684\uff1a \u767b\u9646Linux\u670d\u52a1\u5668\u65f6\uff0c\u5148\u63d0\u793a\u8f93\u5165TOTP\u4e00\u6b21\u6027\u5bc6\u7801\uff0c\u7136\u540e\u518d\u8f93\u5165\u5bc6\u7801\uff0c\u4e24\u4e2a\u90fd\u6b63\u786e\u540e\uff0c\u65b9\u53ef\u4ee5\u767b\u9646\u7cfb\u7edf\u3002TOTP\u5bc6\u7801\u53ef\u4ee5\u4f7f\u7528\u5b89\u5353\u624b\u673a\u7684Google Authenticator\u83b7\u5f97\u3002 \u4e00\u3001Linux\u670d\u52a1\u5668\u7aef\u7684\u914d\u7f6e 1.\u9996\u5148\u53bbhttp:\/\/code.google.com\/p\/google-authenticator\/\u4e0b\u8f7dGA\u7684pam\u5305 2.\u5b89\u88c5 cd libpam-google-authenticator-1.0 make cp pam_google_authenticator.so\u00a0\u00a0\/lib\/security\/ \u4fee\u6539\/etc\/ssh\/sshd_config\uff0c\u4fdd\u8bc1\u6709\u4e0b\u9762\u4e24\u884c ChallengeResponseAuthentication yes UsePAM yes \u4fee\u6539\/etc\/pam.d\/sshd\uff0c\u5728\u7b2c\u4e00\u884c\u6dfb\u52a0 auth\u00a0 \u00a0 \u00a0\u00a0\u00a0required\u00a0 \u00a0\u00a0\u00a0pam_google_authenticator.so 3.\u6267\u884c\u5b89\u88c5\u76ee\u5f55\u5185\u751f\u6210\u7684google-authenticator\u6309\u7167\u63d0\u793a\u8bf4\u5982\u5373\u53ef\u3002\u4e00\u822c\u90fd\u9009\u62e9yes\u3002 \u8fd9\u65f6google-authenticator\u4f1a\u5728\u5f53\u524d\u7528\u6237\u6839\u76ee\u5f55\u4e0b\u751f\u6210\u4e00\u4e2a.google_authenticator\u6587\u4ef6\u3002 \u8fd9\u91cc\u9762\u8bb0\u5f55\u4e86GA\u8ba4\u8bc1\u4f7f\u7528\u7684\u5bc6\u94a5\u3002 [root@s0 libpam-google-authenticator-1.0]# .\/google-authenticator Do you want authentication tokens to be time-based (y\/n) y https:\/\/www.google.com\/chart?chs=200\u00d7200&chld=M|0&cht=qr&chl=otpauth:\/\/totp\/root@s0.ipcpu.com%3Fsecret%3D3YTC5HUNKX6DKQIJ Your new secret […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3,13],"tags":[17],"_links":{"self":[{"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/posts\/301"}],"collection":[{"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/comments?post=301"}],"version-history":[{"count":0,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/posts\/301\/revisions"}],"wp:attachment":[{"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/media?parent=301"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/categories?post=301"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/tags?post=301"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}