Unix
SSH에 2FA (Google authenticator) 적용하기
ForceCore
2022. 11. 15. 14:19
의외로 몹시 쉽다.
Instructions
- https://ubuntu.com/tutorials/configure-ssh-2fa#1-overview 공식 가이드인데 디테일이 조금 부족
- https://dev.to/himadriganguly/configure-ssh-server-with-key-based-and-two-factor-authentication-3oc2 이걸 보고 했다.
- https://serverfault.com/questions/1073593/ssh-public-key-authentication-with-google-authenticator-still-asks-for-password 여기도 같은 맥락의 답이 달려있다.
- sudo apt install libpam-google-authenticator로 인증기 설치
- /etc/pam.d/ssh 수정을 하는데 common-auth 는 꺼야 함. (공식 가이드에 없는 부분)
# Standard Un*x authentication.
# @include common-auth
- 그리고 맨 아래에 OTP auth를 적는다.
# Standard Un*x password updating.
@include common-password
# And 2FA
auth required pam_google_authenticator.so
- /etc/ssh/sshd_config 수정을 하는데, 공식 가이드에 없는 것이 있다.
# For 2FA
ChallengeResponseAuthentication yes # 이거는 켜고
# To disable tunneled clear text passwords, change to no here!
PasswordAuthentication no # 이거는 AWS에서는 꺼져있다
#PermitEmptyPasswords no
# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
KbdInteractiveAuthentication no # 이거도 꺼져있고
AuthenticationMethods publickey,keyboard-interactive # 이거는 반드시 추가
- sudo systemctl restart sshd.service
- 유저별로 google-authenticator 명령을 실행시켜서 TOTP setup을 해야지 된다.
- 이제 ssh로 서버에 접속이 잘 되는지 확인을 한다.
- 이후 다른 유저를 추가할 시, sudo su - USER_ID 로 “로그인” 한 뒤에 TOTP setup을 해줘야 함.