# SSH 啟用 OTP 驗證功能 ## 安裝必要套件 ``` sudo apt install libpam-google-authenticator ``` ## 編輯 `/etc/ssh/sshd_config` 調整 KbdInteractiveAuthentication , ChallengeResponseAuthentication 設定 ```text 略.. # Change to yes to enable challenge-response passwords (beware issues with # some PAM modules and threads) KbdInteractiveAuthentication yes ChallengeResponseAuthentication yes 略.. ``` ## 編輯 /etc/pam.d/sshd 在 @include common-auth 後面新增 下面內容 ``` @include common-auth # 加入 otp 的驗證 , nullok 當使用者沒啟用 otp 時不強制檢查 # 如果拿掉 nullok , 使用者一定要先設定好 otp 才能登入 auth required pam_google_authenticator.so nullok ``` ## 已使用者身份執行 google-authenticator 根據畫面的步驟操作後,會在家目錄下產生一個 .google_authenticator 檔案,這檔案的權限一定要是 400。 過程中畫面會產生一個QRCODE,用 Microsoft Authenticator , Google Authenticator 之類的工具程式掃描,就可以登錄進手機了。 ## 測試 完成上面設定後,在 ssh 登入主機應該就會先問密碼,驗證完密碼就會跳出 OTP 驗證,從手機取得正確 OTP 輸入後就可以登入主機工作了。
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up