Amazon Linux 2023에서 Google Authenticator 적용하기

2025. 4. 18. 21:36AWS

오늘은 Amazon Linux 2023에서 Google Authenticator를 적용하는 방법에 대해 서술하려고 한다.

구글링을 조금 했는데, 하란대로 해도 적용이 안되서 애를 조금 먹었었지만, 방법을 찾기는 했다.

 

사실 수요일에 올렸어야 했지만, 잘 안되서 포기하고 목요일에는 무려 자정을 넘겨서까지 야근을 하는 바람에 작성이 늦어졌다.

 

Google Authenticator 패키지 설치

sudo dnf install google-authenticator

해당 명령어로 설치한다.

만약 설치가 되지 않는다면 Kernel 버전이 낮아서 그럴 가능성이 있다.

amazon linux repository의 이슈AL2023.2 Release notes를 통해 버전때문에 설치가 안되었던 것 같아 커널도 업데이트 했다.

 

이후 설정을 진행하면 된다.

2FA 인증을 적용할 계정에 접속한 후 명령어를 입력한다.

google-authenticator

 

각 질문과 설정들은 아래와 같다.

Do you want authentication tokens to be time-based (y/n) : Time-based token 사용할거에요?

이 질문에 y를 입력하면 secret key가 나타난다. (Amazon Linux 2 AMI 에서는 사진이 나온다고 한다.)

2FA Secret Key

 

이후 이 키를 통해 등록한 OTP 키를 입력하면 된다.

나는 Chrome의 확장 프로그램으로 Google Authenticator를 다운로드 해 설정했다.

Chrome Google Authenticator

필요하다면 여기에서 다운로드 해서 사용하자.

 

 

Do you want me to update your "/home/pooooobi/.google_authenticator" file? (y/n) : .google_authenticator 파일 덮어쓸거에요?

y 입력하면 된다.

 

your chances to notice or even prevent man-in-the-middle attacks (y/n) : 로그인 시 토큰 재사용을 방지할거에요?

 

간단하게 설명하면 Tabby는 해당사항이 없을테지만 WinSCP 같은 프로그램에서 먼저 접속 하고, Putty 창을 띄우는 경우가 많은데, 이때 토큰 계속 재사용해서 쓸 수 있게할거야? 라는 뜻이다.

개인적으로는 가장 싫어하는 옵션중에 하나인데, 운영 환경이라면 적용했을거지만.. 내용 전달용이니 굳이 적용하지는 않았다.

 

By default, a new token is generated every 30 seconds by the mobile app.
In order to compensate for possible time-skew between the client and the server,
we allow an extra token before and after the current time. This allows for a
time skew of up to 30 seconds between authentication server and client. If you
experience problems with poor time synchronization, you can increase the window
from its default size of 3 permitted codes (one previous code, the current
code, the next code) to 17 permitted codes (the 8 previous codes, the current
code, and the 8 next codes). This will permit for a time skew of up to 4 minutes
between client and server.
Do you want to do so? (y/n) : 시스템 시계 오차 허용할거에요?

 

y 하면 된다. 가끔 서버시간이 빠르거나, 느린 경우가 있는데 내 경우엔 12분까지 봤었다. (물론 이경우에는 접속 안됨)

파이썬으로 OTP 키 만들어서 겨우 접속했던 기억이 있다.....

 

If the computer that you are logging into isn't hardened against brute-force
login attempts, you can enable rate-limiting for the authentication module.
By default, this limits attackers to no more than 3 login attempts every 30s.
Do you want to enable rate-limiting? (y/n) : 비상 코드를 저장할건가요?

 

취향이다.

 

이후 Linux 설정을 변경해야 한다.

 

Linux 설정 변경

sudo vi /etc/pam.d/sshd

에서 사진을 참고해 auth required pam_google_authenticator.so nullok 를 입력한다.

/etc/pam.d/sshd

 

sudo vi /etc/ssh/sshd_config.d/50-redhat.conf

이 부분은 다른 글과 주의가 필요하다.

다른 글에서는 /etc/ssh/sshd_config를 수정하라고 했지만, Amazon Linux 2023 보안으로 ssh_config.d/50-redhat.conf가 먼저 적용되기 때문에 여기에 적용해야 한다.

/etc/ssh/sshd_config.d/50-redhat.conf

 

이후 ssh 서비스를 재시작 하고 다시 접속을 시도해본다.

이상 없이 접속할 수 있다.

 

혹시나 안되거나 한다면 pam의 순서가 바뀌거나 했을 수 있으니 참고해야 한다.

반응형

'AWS' 카테고리의 다른 글

AWS Client VPN 구성해보기  (0) 2025.04.12