FastNetMon

Wednesday 27 April 2011

Как ограничить ssh пользователя, входящего в систему по сертификатам лишь заданным диапазоном IP?

Итак, у нас есть Linux пользователь, который входит в систему по ssh с использованием ключей - парольная аутентификация запрещена. Задача - как ограничить пользователю возможный диапазон IP, с которых он входит в систему.

Вариант 1.

Задать диапазон хостов, с которых может входить юзер можно посредством директивы AlloUsers в /etc/ssh/sshd_config.

Вот цитата из официальной документации (man sshd_config):
AllowUsers This keyword can be followed by a list of user name patterns, separated by spaces. If specified, login is allowed only for user names that match one of the patterns. ‘*’ and ‘?’ can be used as wildcards in the patterns. Only user names are valid; a numerical user ID is not recognized. By default, login is allowed for all users. If the pattern takes the form USER@HOST then USER and HOST are separately checked, restricting logins to particular users from particular hosts.

Но, очевидно, каждый раз дергать конфиги такого важного демона как ssh для изменения IP крайне неправильно.

Вариант 2.

Использовать поле options в файле authorized_keys: from "ip_addr".

Выглядеть это будет так:
from "ip_addr" ssh-rsa AAAABтут_много_букв_которые_представляю_собой_ключ_в_base64== test@yandex.ru

Подробное описание из документации (man 8 sshd):
from="pattern-list"

Specifies that in addition to public key authentication, the canonical name of the remote host must be present in the comma-separated list of patterns (‘*’ and ‘?’ serve as wildcards). The list may also contain patterns negated by prefixing them with ‘!’; if the canonical host name matches a negated pattern, the key is not accepted. The purpose of this option is to optionally increase security: public key authentication by itself does not trust the network or name servers or anything (but the key); however, if somebody somehow steals the key, the key permits an intruder to log in from anywhere in the world. This additional option makes using a stolen key more difficult (name servers and/or routers would have to be compromised in addition to just the key).

2 comments :

  1. ip_addr можно указать в формате "сеть/префикс"?

    ReplyDelete
  2. Немного расширил пост цитатой из оф доки, в таком формате, как я понял, нельзя, но можно в формате с wildcard: 192.168.10.*

    ReplyDelete

Note: only a member of this blog may post a comment.