Pull to refresh

SSH с авторизацией через Google Authenticator. | Two Factor SSH with Google Authenticator

Многие уже наверное оценили двухступенчатую авторизацию от google, ниже я расскажу как ей воспользоватся для ssh авторизации на сервере debian. Пользователи Ubuntu так же могут ориентироваться на данную статью.

Итак, приступим, в Debian есть готовый пакекет libpam-google-authenticator тоесть ничего собирать не надо.

Установим libpam-google-authenticator.
# apt-get install libpam-google-authenticator

Отредактируем файл /etc/pam.d/sshd.
# nano /etc/pam.d/sshd
Добавим в начало файла строку
auth required pam_google_authenticator.so
и сохраним изменения (ctrl + x, Yes, Enter).

Далее откроем файл /etc/ssh/sshd_config и внесем в него необходимые изменения.
# nano /etc/ssh/sshd_config
Находим ChallengeResponseAuthentication (поиск в nano — ctrl + w)
и меняем ChallengeResponseAuthentication no на ChallengeResponseAuthentication yes
затем сохраняем изменения (ctrl + x, Yes, Enter).

Теперь настроим сам Google Authenticator.

# google-authenticator
Сразу же получаем необходимую информацию для настройки приложения Google Authenticator, а так же запасные коды.

На вопросы
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.

Теперь достаточно перезапустить sshd для применения изменений.
# service ssh restart

Теперь во время логина нужно вводить еще и Verification code.
image

Идеей послужила статья www.mnxsolutions.com/security/two-factor-ssh-with-google-authenticator.html.
Tags:
Hubs:
You can’t comment this publication because its author is not yet a full member of the community. You will be able to contact the author only after he or she has been invited by someone in the community. Until then, author’s username will be hidden by an alias.