YUMSERV
article thumbnail
반응형

OTP는 ONE TIME PASSWORD로 일정시간마다 생성되는 일회성 패스워드로, 주로 은행권에서 많이 사용되고 있습니다.

일반적으로 서버를 로그인할 때, 패스워드만 입력하는 것이 아니라, 패스워드 + OTP를 이용하면 보안상으로 더 안전하게 보호할 수 있습니다.


1. 리눅스에 설치

※ CentOS 7 환경에서 셋팅 진행


1) Google Authenticator 설치

# yum install google-authenticator


2) PAM 모듈 설정

pam 모들을 사용하기 위해 google authenticator 라이브러리를 추가해줍니다.


# vi /etc/pam.d/sshd

아래 줄을 추가해줍니다.

auth    required    pam_google_authenticator.so nullok


3) SSH 설정

# vi /etc/ssh/sshd_config

PermitEmptyPasswords no

PasswordAuthentication no
UsePAM yes

ChallengeResponseAuthentication yes


[아래 설명]

PermitEmptyPasswords 비어있는 사용자 암호를 허용할 것인가

PasswordAuthentication 패스워드 인증을 사용할 것인가. OTP인증시에는 사용하지 않습니다.

UsePAM PAM 모듈을 사용할 것인가

ChallenageResponseAuthentication 시도응답 방식을 사용할 것인가


설정 변경 후 ssh 서비스를 재시작 해줍니다.

# service sshd restart


4) 네트워크 시간동기화

OTP를 사용하기위해서는 시간이 동기화가 되어있어야 합니다.

시간동기화를 위해 NTP 서비스를 설치하고, 시작해주었습니다.


# yum -y install ntp

# service ntp start


5) OTP 생성


접속할 계정에 로그인한 뒤에, 아래의 명령어를 통해 인증파일을 생성해줍니다.

# google-authenticator


Do you want authentication tokens to be time-based (y/n) y

시간 기반인증을 사용할 것인가? yes 입력합니다.

넘어가게 되면 아래와 같이 QR코드와 시크릿 키가 나오게 됩니다.
QR코드가 제대로 안보일 경우, 터미널의 크기나, 글자크기를 변경하면 보이게 됩니다.
QR코드 밑에는 시크릿 키가 존재하는데, 시크릿 키는 토큰값으로, 개인키와 같은 역할을 하므로, 절대 공유해서는 안됩니다.


Warning: pasting the following URL into your browser exposes the OTP secret to Google:
  https://www.google.com/chart?chs=200x200&chld=M|0&cht=qr&chl=otpauth://totp/root@localhost%3Fsecret%3D[secretkey]%26issuer%3Dlocalhost
QR코드
Your new secret key is: SECRETKEY
Your verification code is ######
Your emergency scratch codes are:
  ########
  ########
  ########
  ########
  ########

핸드폰에 Google OTP를 설치한 뒤에, 바코드 스캔으로 QR코드를 스캔하거나, SECRET key를 입력합니다.

Do you want me to update your "/root/.google_authenticator" file? (y/n) y
위 디렉토리에 파일을 생성하겠다는 의미로, yes 입력합니다.

Do you want to disallow multiple uses of the same authentication
token? 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
30초마다 생성되는 토큰에 두번 인증하게 하여 중간자 공격을 막을 것인지 여부로 yes로 입력합니다.

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) n
시간동기화를 진행하면서 발생하는 시간상 오차를 방지하는 옵션으로, 허용범위를 넓힐지 여부를 물어보는 것으로, no로 입력합니다.

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) y

무차별 대입공격을 방지하기 위한 설정으로 30초마다 생성되는 토큰에 3회이상 인증 실패시, 일시적으로 로그인을 차단하는 내용입니다. yes를 입력합니다.


6) ssh 접속

# ssh 계정명@IP주소

Password: 기본 password

Verification code: OTP 코드



반응형

'LINUX > 보안' 카테고리의 다른 글

GeoIP 셋팅  (0) 2021.08.29
리눅스 해킹점검  (0) 2019.07.07
ClamAV 무료 백신 사용  (0) 2019.07.07
Telegram봇을 통해 ssh 접속 로그 확인  (0) 2019.07.05
profile

YUMSERV

@lena04301

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!