在 OS 中可以限制哪些使用者可以訪問
(1) 大致可以分類為 User Account, Superuser Account, System Account, Service Account
(2) user 登入 設定會存於 /etc/passwd, /etc/shadow, /etc/group
(3) 可設定 user nologin, 或者將不適用的 user 進行刪除
今天主要會針對 ssh 介紹
ssh <hostname/IP>
(2) 透過指定 User 名稱登入
ssh <User>@<hostname/IP>
(3) 使用 key 登入
ssh -i <key.pem> <User>@<hostname/IP>
ssh-keygen -t iroman
~/.ssh/authorized_keys
# /etc/ssh/sshd_config
PermitRootLogin no # 無法使用 PermitRootLogin
PasswordAuthentication no # 無法使用 password 登入
(1) 安裝 google-authenticator
sudo apt install libpam-google-authenticator
(2) 修改配置檔
# vim /etc/ssh/sshd_config
PasswordAuthentication no #可以不用使用密碼
ChallengeResponseAuthentication yes #允許驗證
UsePAM yes #可以使用PAM
AuthenticationMethods publickey,keyboard-interactive:pam #可以使用public key 及PAM
# vim /etc/pam.d/sshd
確保文件中包含以下行(通常在頂部附近):
nullok 參數允許沒有設置 Google Authenticator 的用戶仍然可以登錄。
在同一個文件中,找到並註釋掉(在行首添加 #)要求輸入密碼的行。通常是這樣的:
Copy# @include common-auth
加上
auth required pam_google_authenticator.so
(3) 重啟 sshd
sudo systemctl restart sshd
(4) 設定 MFA
google-authenticator
(5) 輸入後會出現 MFA 的QR code,與一般 MFA 綁定過程相同
參考資料
https://stackoverflow.com/questions/71657716/2fa-is-not-working-with-ubuntu-aws-instance