Unix

SSH에 2FA (Google authenticator) 적용하기

ForceCore 2022. 11. 15. 14:19

의외로 몹시 쉽다.

 

Instructions

# 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을 해줘야 함.