ssh google OTP MFA

2020-10-17 10:06:322023-01-27 23:47:12
top
before

ssh google OTP MFA

2020-10-17 10:06:322023-01-27 23:47:12

ssh를 밖에서 접근할수 있도록 포트 오픈하고 있었는데
포트를 열어두자니 누군가 bf공격을 하면 혹시 열릴수 있을것 같고
IP로 하나하나 인바운드를 막는것이 귀찮고
나는 밖에서 접근하고 싶고 하여서 
MFA를 하게되면 좀더 괜찮아 지지 않을까 싶어서 적용하였다.

https://github.com/google/google-authenticator-libpam

우분투에서는 apt를 통해 설치가 가능했다

sudo apt install libpam-google-authenticator

그리고 /etc/pam.d/sshd 에 다음 줄을 추가 하면 접근시 MFA 인증을 필요로 하게된다.

auth required pam_google_authenticator.so nullok

(22 이후)

auth required pam_google_authenticator.so nullok
auth required pam_permit.so

마지막에 nullok 옵션을 설정하여야 google authenticator 설정이 홈에 있는 계정에 대해서만 제한할수 있다고 한다.

그리고 /etc/ssh/sshd_config 에 UsePAM 을 yes로 하고

UsePAM yes

ChallengeResponseAuthentication yes
(22 이후)
KbdInteractiveAuthentication yes
 

계정에서 google-authenticator를 실행하면 홈디렉토리에 google_authenticator 가 생성이 되고 활성화 된다.

google-authenticator -t -d --label=pllip -w 3 -e 10 -r 3 -R 30

-t : 시간 기반 OTP
-d: 지난 토큰 재사용 금지
-w: 허용할 이전 코드 수
-e: emergency code 생성 수
-r: 로그인 시도 제한 수
-R: 로그인 시도 제한 시간  

 이와 같이 실행하면 화면에 생성한 OTP 정보와 QR코드가 출력이되고 google OTP 앱에서 읽어서 사용할수 있었다.

 

 

ps.
지금 본업으로 하고 있는 비지니스(호텔)에서 OTA라는 용어를 많이 사용하다보니, 그렇게 작성하고 발행하여 버렸었네...

ps.2
연결이 되어있을때는 몰랐는데, jenkins에서 접근할때에도 verification 이 필요하여 접근을 못하고 있었다.

/etc/security/access-local.conf 파일을 만들고 

# only allow from local IP range
+ : ALL : xxx.xxx.xxx.xxx #jenkins 서버 IP
+ : ALL : LOCAL
- : ALL : ALL

 를 저장하고

/etc/pam.d/ssh 파일에

auth [success=1 default=ignore] pam_access.so accessfile=/etc/security/access-local.conf

 를 추가하였다.