카테고리 없음

CentOS 7에서 Google Authenticator를 사용 설정하여 2단계 인증(2FA/MFA) 설정

DKel 2024. 5. 24. 18:04
반응형

# 2단계 인증(2FA)
2단계 인증(2FA)은 로그인 시 사용자 인증에 2개의 개별 자격 증명을 제공하는 프로세스입니다. 때때로 둘 이상의 자격 증명이 사용되며 멀티팩터 인증(MFA)이라고 합니다.

이중 인증은 비밀번호 크래킹, 비밀번호 유출 등으로 인한 보안 위험에 대해 효과적으로 방어할 수 있습니다. 공격자가 암호를 가지고 있어도 2단계 인증을 통과할 수 없는 자격 증명 하나만 있습니다.

일반적으로 이중 인증의 첫 번째 자격 증명은 Google이 알고 있는 비밀번호이며 두 번째 자격 증명은 Google Authenticator와 같은 토큰 코드 또는 휴대전화의 SMS 인증 등일 수 있습니다.

Google Authenticator 인증 코드는 타임스탬프를 기준으로 계산된 숫자 집합으로 30초마다 업데이트됩니다. 공식 용어는 "타임베이스의 일회용 암호 알고리즘"(TOTP)입니다. 인터넷 연결은 필요하지 않으며 언제든지 인증에 사용할 수 있습니다.

Google Authenticator 설치 및 초기화
먼저 EPEL 소스를 추가합니다.

yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm


루트 사용자를 사용하지 않는 경우 명령을 실행하는 데 사용해야 할 수 sudo있습니다.

그런 다음 Google Authenticator를 설치합니다.

yum install google-authenticator


그런 다음 초기화해야 합니다.

google-authenticator



페이지에는 거대한 QR 코드가 표시됩니다. 이 시점에서 Google Authenticator 또는 유사한 인증 앱을 사용하여 QR 코드를 스캔하여 휴대전화에 추가합니다.

그런 다음 앱은 몇 가지 질문을합니다. 모두를 y입력하고 Enter를 누르십시오.

# Do you want to use time-based tokens?
Do you want authentication tokens to be time-based (y/n) y
# Do you want to update the configuration file?
Do you want me to update your "/root/.google_authenticator" file (y/n) y
# Do you want to set disallow multiple uses of the same token?
Do you want to disallow multiple uses of the same authentication
This restricts you to one login about every 30s, but it increases
your chances to notice or even prevent man-in-the-middle attacks (y/n) y
# Do you allow tokens within a 1-minute time error before and after?
By default, tokens are good for 30 seconds.
possible time-skew between the client and the server, we allow an extra
token before and after the current time.
poor time synchronization, you can increase the window from its default
If you experience problems with poor time synchronization, you can increase the window from its default size of +1min (window size of 3) to about +-4min (window size of 17 acceptable tokens).
Do you want to do so? (y/n) y


이 시점에서 Google Authenticator가 설치되었습니다.

# PAM 인증
PAM(Plugable Authentication Module) 인증은 Linux 시스템의 플러그 가능 인증 방법이며 새 인증 방법을 추가해야 하는 경우 해당 PAM 모듈을 추가하기만 하면 됩니다.

위에서 설치한 Google Authenticator도 PAM 모듈입니다.

따라서 먼저 sshd에서 사용하는 PAM 구성에서 Google Authenticator 인증을 사용하도록 설정합니다. /etc/pam.d/sshd의 두 번째 행 아래에 다음 행을 추가합니다.

auth required pam_google_authenticator.so



주의: 이 행의 위치는 매우 중요하며 변경된 파일은 다음과 같아야 합니다.

#%PAM-1.0
auth       required     pam_sepermit.so
auth       required     pam_google_authenticator.so
auth       substack     password-auth


# other lines
......

 

그런 다음 sshd 설정에서 챌린지 인증을 사용하도록 설정해야 합니다. /etc/ssh/sshd_config에서 다음 설정을 찾아서 yes변경하십시오.

# Change to no to disable s/key passwords
ChallengeResponseAuthentication yes
#ChallengeResponseAuthentication no


2차 인증을 사용하려면 sshd 서비스를 다시 시작하십시오.

설정 파일
Google Authenticator 설정 파일은 /root/.google_authenticator에 있습니다. 필요한 경우 를 사용하여 cat /root/.google_authenticator볼 수 있습니다.

구성 파일에는 키 + 구성 + 복구 코드의 세 부분이 있습니다.

키는 토큰의 결과를 결정하고 동일한 키는 동일한 토큰을 생성합니다. 따라서 여러 서버에서 동일한 토큰을 사용하는 경우 해당 키를 동일한 값으로 설정할 수 있습니다.

복구 코드는 인증 앱이 분실된 경우 응급 복구에 사용되며 안전한 장소에 보관해야 합니다.

반응형