1. 程式人生 > >centos google authenticator 安裝及配置

centos google authenticator 安裝及配置

google authenticator

為了增強服務器安全性,使用google authenticator生成的動態密碼進行加固,輸入密碼的同時需要再次驗證動態密碼才能登錄成功。以下操作均在centos6.5環境下操作。


首先:

1、安裝一些必要組件

yum install -y git make gcc libtool pam-devel qrencode ntpdate


2、下載編譯安裝

git clone https://github.com/google/google-authenticator-libpam.git
cd google-authenticator-libpam/
./bootstrap.sh
./configure
make && make install
ln -s /usr/local/lib/security/pam_google_authenticator.so /usr/lib64/security/


3、配置ssh

vim /etc/ssh/sshd_config

修改如下的配置項:

ChallengeResponseAuthentication yes

UsePAM yes

重啟ssh

service sshd restart


4、配置PAM

vim /etc/pam.d/sshd

如下:

#auth include password-auth

auth substack password-auth

auth required pam_google_authenticator.so

第一行刪除或者註釋,第二行和第三行的順序將確定先輸入密碼還是動態碼


5、配置google authenticator

首先,切換到你需要設置的帳號:

su google
google-authenticator

Do you want authentication tokens to be time-based (y/n) y ---輸入y(會生成一個二維碼和secret key,之後的操作會用到這個二維碼/密鑰(secret key),還有5 個緊急救助碼(emergency scratch code),緊急救助碼就是當你無法獲取認證碼時(比如手機丟了),可以當做認證碼來用,每用一個少一個,但其實可以手動添加的,建議如果 root 賬戶使用 Google Authenticator 的話一定要把緊急救助碼另外保存一份。)

Warning: pasting the following URL into your browser exposes the OTP secret to Google:

https://www.google.com/chart?chs=200x200&chld=M|0&cht=qr&chl=otpauth://totp/google@ip-172-31-17-35%3Fsecret%3DEUMUWLYHE3WFDCD4FTTC4NHDWU%26issuer%3Dip-172-31-17-35

---如果已經安裝qrencode,此處會顯示二維碼,該二維碼也可以通過上面的網址打開---


Your new secret key is: EUMUWLYHE3WFDCD4FTTC4NHDWU

Your verification code is 102411

Your emergency scratch codes are:

31858704

90298886

63354215

17985381

56998209


Do you want me to update your "/home/google/.google_authenticator" file? (y/n)y ---輸入y(是否更新用戶的 Google Authenticator 配置文件,選擇 y 才能使上面操作對當前用戶生效,其實就是在對應用戶的 Home 目錄下生成了一個 .google_authenticator 文件,如果你想停用這個用戶的 Google Authenticator 驗證,只需要刪除這個用戶 Home 目錄下的 .google_authenticator 文件就可以了。)


Do you want to disallow multiple uses of the same authentication

token? This restricts you to one login about every 30s, but it increases

your chances to notice or even prevent man-in-the-middle attacks (y/n)y ---輸入y(每次生成的認證碼是否同時只允許一個人使用?這裏選擇 y)


By default, a new token is generated every 30 seconds by the mobile app.

In order to compensate for possible time-skew between the client and the server,

we allow an extra token before and after the current time. This allows for a

time skew of up to 30 seconds between authentication server and client. If you

experience problems with poor time synchronization, you can increase the window

from its default size of 3 permitted codes (one previous code, the current

code, the next code) to 17 permitted codes (the 8 previous codes, the current

code, and the 8 next codes). This will permit for a time skew of up to 4 minutes

between client and server.

Do you want to do so? (y/n)n ---輸入n(是否增加時間誤差?這裏選擇 n )


If the computer that you are logging into isn‘t hardened against brute-force

login attempts, you can enable rate-limiting for the authentication module.

By default, this limits attackers to no more than 3 login attempts every 30s.

Do you want to enable rate-limiting? (y/n)y ---輸入y(是否啟用次數限制?這裏選擇 y,默認每 30 秒最多嘗試登錄 3 次)


6、APP設置

首先從google play 下載google Authenticator,打開app,點擊"scan a barcode",掃一下剛剛生成的二維碼,或者手動輸入secret key,即可得到一個動態密碼,該密碼每30秒變化一次。使用ssh登錄服務器時,需要先輸入用戶密碼,再輸入動態密碼才可以登錄。

技術分享

7、動態密碼登錄


[deploy@puppet c]$ ssh [email protected]

Password:

Verification code: ---此處輸入動態密碼---


如果出現異常,請查看/var/log/secure進行排查


參考內容:

http://shenyu.me/2016/09/05/centos-google-authenticator.html

http://www.111cn.net/sys/CentOS/88306.htm

本文出自 “10059777” 博客,請務必保留此出處http://10069777.blog.51cto.com/10059777/1973790

centos google authenticator 安裝及配置