Bastion Host安裝google-authenticator,googleauthenticator

來源:互聯網
上載者:User

Bastion Host安裝google-authenticator,googleauthenticator

  公司線上的使用機器不能讓使用者隨意的登陸,所以就不能讓開發隨意的登陸到生產的機器的。於是就打算使用google-auth的驗證方式呢。

  如果google-auth的方式。

 搭建google-authenticator:

  搭建這個很簡單,如下:

  git clone https://github.com/google/google-authenticator-libpam 下載最新的google auth 最新版。

  cd google-authenticator-libpam/

  ./bootstrap.sh

  ./configure && make && make install

  ln -s /usr/local/lib/security/pam_google_authenticator.so /lib64/security/pam_google_authenticator.so

  修改/etc/pam.d/sshd,

  #最上方加一行 "auth required pam_google_authenticator.so"
   #這個配置可以更複雜一些,加上一些參數,詳見 libpam/README
   #註:如果遇到仍然需要輸入密碼的情況,改成 "auth sufficient pam_google_authenticator.so" 試試。

  修改/etc/ssh/sshd_config

  將 ChallengeResponseAuthentication 選項的 no 改成 yes

  將 UsePAM yes

  service sshd restart

   產生密鑰

  $ google-authenticator    #註:運行這個命令的是需要登入的使用者,不是root使用者
  Do you want authentication tokens to be time-based (y/n) y  (確認:基於時間的認證token)
  【這裡會顯示產生二維碼的地址、二維碼、密鑰明文、應急碼】
  Do you want me to update your "/var/www/.google_authenticator" file (y/n) y (確認:更新設定檔)
  ......
  size of 1:30min to about 4min. Do you want to do so (y/n) n (token有效期間是1.5min,選y就是4min)
  ......
  Do you want to enable rate-limiting (y/n) y (30s內只允許嘗試三次)

  在app裡掃二維碼,或者手動輸入密鑰,即可看到token每隔30s更新一次了

  嘗試登入
  $ ssh localhost
  verification code: 【輸入驗證碼】
  password: 【輸入密碼】

 

 

補:

但當時只是簡單加上了Google Authenticator,實際使用中既要輸入驗證又要輸入密碼,太繁瑣了,所以在搭建我司跳板機的時候,選擇了用 publickey + authenticator 的方案,只需要輸入一次驗證碼即可。但是這裡要求很多。如openssh的版本大於6.2,如果不是的話,就無法使用AuthenticationMethods,最好的方式是使用centos7的版本(已驗證過可以使用)centos6.5測試無法使用(應該是我技術不行)。

具體的配置方案變化不大,主要是用上了 SSH 6.2+ 新增的 AuthenticationMethods 參數,可以指定一系列驗證方法,具體配置如下:

引用#預設需要先用publickey驗證,再用驗證碼
AuthenticationMethods publickey,keyboard-interactive

#對於指定的IP,只需要publickey驗證
Match Address 10.0.0.4
    AuthenticationMethods publickey

#也可以指定使用者只需要publickey驗證
#Match User XXX
    #AuthenticationMethods publickey



順便吐槽一下,Linux這套東西折騰起來真是要命,今天配置跳板機備份機的時候,完全相同的配置,複製一份就是不對,雖然配置裡只指定了publickey,keyboard-interactive,但是每次輸完驗證碼以後還是要求輸入密碼才行,折騰了幾個小時才發現,不知道從什麼時候開始,"auth required pam_google_authenticator.so" 已經不合適了,需要改成 "auth sufficient pam_google_authenticator.so",這樣才會在輸入驗證碼以後就結束認證過程(sufficient的實現裡加了一個break?什麼鬼。)(感謝 @ https://serverfault.com/a/740881/343388)


最後,提醒一下使用SecureCRT的同學,你需要在Session Options -> Connection -> SSH2,將Authentication中只選用 "Keyboard Interactive" ,否則沒法正常登入。

  錯誤:configure: error: Unable to find the PAM library or the PAM header files

  方法:yum install -y pam-devel

  

引用:https://www.felix021.com/blog/read.php?2133

   https://www.felix021.com/blog/read.php?2172 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.