Translate

2012/11/22

Secure SSH with Google Authenticator

얼마전에 노트북의 wol 기능을 사용하여 외부에서 노트북을 사용하고 싶었지만 어떤 문제로 인해서 wol을 사용할 수 없었다. 하지만 노트북이 필요할 경우 켜두고 간 다음 ssh를 사용해 접속을 하면 관리하기 편하기 때문에 이렇게 사용하려고 한다.

약간의 걱정이 있다면 암호가 간단하여 보안에 문제가 있다고 생각하거나 불안함을 느끼는 분들을 위해서 google authenticator 어플(ios, 안드로이드, 블랙베리로 나와 있다고 한다.)을 사용하여 보안을 높이고자 한다.

이 어플까지 사용을 하면 1차로 암호를 물어보고 2차로 인증번호가 주어지는데 제한시간 안에 번호를 입력해야한다. 이정도면 ssh가 뚫리지 않는 이상 걱정이 없을 거 같다.

debian이나 ubuntu를 사용하시는 분들은 다음 사항을 그대로 따라하시면 된다.

1. 먼저 설치를 한다.

$ sudo apt-get install libpam-google-authenticator

2.무른모를 설정

$ google-authenticator
...
<QR code>

Your new secret key is: xxx
Your verification code is

Your emergency scratch codes are:
1234
5678
....

실행을 하면 QR코드가 크게 뜨는데 일단은 무시하고 secret key 부분과 emergency scratch code는 반드시 다른 곳에 복사해 둔다. 중요한 정보이므로 함부로 노출되지 않도록한다. (이 key가 인증번호 생성기를 인증하는 키가 된다.)



Do you want me to update your "~/.google_authenticator" file (y/n) y

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

By default, tokens are good for 30 seconds and 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. If you experience problems with poor
time synchronization, you can increase the window from its default
size of 1:30min to about 4min. Do you want to do so (y/n) n

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. 시간 설정

자세한 원리는 모르지만 시간에 맞춰서 인증번호를 바꾸기 때문에 컴퓨터 시간 동기화가 필요하다. 이 명령어도 잘 모르기에 그냥 이렇게 실행을 하면 동기화가 된다고 한다.

$ sudo apt-get install ntp
$ ntpq -np

*211.233.84.186  204.123.2.5      2 u   51   64  377    8.953   10.064  14.880

이런식으로 별로가 들어간 항목이 있어야한다고 하는데 찾아보지 않아서 잘 모르겠다. 궁금하신분들은 구글신께 기도하세요.

4. ssh 설정

$ sudo vi /etc/ssh/sshd_config

ChallengeResponseAuthentication 이 항목을 찾아서 no로 되어 있다면 yes로 바꿔준다.
저장 후 ssh를 재시작 한다.

$ sudo /etc/init.d/ssh restart
$ sudo vi /etc/pam.d/sshd
auth required pam_google_authenticator.so 이 내용을 마지막에 추가한다.

5. 어플 설치

play store에서 google otp라는 어플을 찾아서 실행을 한다.
처음에 실행을 하면 QR코드 입력이나 수동 입력이 있는데 둘 중에 원하는걸 선택한다.

QR코드 입력을 선택한 경우에는 1번에서 나온 QR코드를 사용하거나 url 주소를 이용하면 되고
수동 입력의 경우에는 secrect key를 입력하면 된다. ㅋ

이제 ssh를 접속해 보면 2단계 인증을 할 수 있을 것이다.


좀 더 나은 보안을 사용해 내 컴퓨터를 지키도록 하자~~
(이것으로 우리는 스마트폰에 더욱 신경써야 한다는 결론을 얻게 됐다. ㅋㅋㅋ)


다음에는 ssh tunnel 기능을 사용해 vnc를 실행해 보도록 하겠다. 물론 android에서 까지 가능하도록...


Ref.
http://www.lylebackenroth.com/blog/2012/04/25/leveraging-googles-two-factor-identification-to-secure-ssh-logins/
http://www.howtogeek.com/121650/how-to-secure-ssh-with-google-authenticators-two-factor-authentication/

댓글 없음:

댓글 쓰기

Template by Aliya H.