Translate

Показ дописів із міткою ssh. Показати всі дописи
Показ дописів із міткою ssh. Показати всі дописи

пʼятниця, 4 жовтня 2013 р.

Контроль удаленного доступа с помощью pam_access.



     Для начала надо включить pam_access модуль. Раскомментировать строку в /etc/pam.d/login и /etc/pam.d/sshd:

account  required       pam_access.so

 

Защищаем административный логин:

     Изменяем /etc/security/access.conf для запрета удаленных соединений к административным и к другим аккаунтам:
#
# Disallow non-root logins on tty1
#
- : ALL EXCEPT root : tty1
#
# Allow root login on tty1
+ : root : tty1
#
# Disallow console logins
- : ALL : LOCAL
#
# ...
#
# User "root" should be denied to get access from all
# other sources
- : root : ALL

 

Защищаем сетевые соединения:

     Задаем группу, которой будет разрешен удаленный доступ (через ssh).
groupadd -r sshusers


Изменяем /etc/security/access.conf in order to allow only sshusers group network access.
# Allow group 'sshusers' get access from everythere
+ : (sshusers) : ALL
#
# All other users should be denied to get access from
# all sources.
- : ALL : ALL

Настройки беcпарольного доступа.

     Если необходимо настроить так, чтобы можно было логиниться на хост без ввода пароля, нужно сделать следующее:

1. Сгенерировать частный и общественный ключи:
      
user1@host1:~$ ssh-keygen -t rsa
     
Generating public/private rsa key pair.

Enter file in which to save the key (/home/user1/.ssh/id_rsa):

Created directory '/home/user1/.ssh'.

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in /home/user1/.ssh/id_rsa.

Your public key has been saved in /home/user1/.ssh/id_rsa.pub.

The key fingerprint is:

81:95:1a:bd:32:89:3b:c7:34:da:a2:a0:14:24:26:73 user1@host1

The key's randomart image is:

+--[ RSA 2048]----+

|       ...       |

|+oE   .oo        |

|=o   ..+..       |

| .  . B ..       |

|  .  * +S        |

|..  = +          |

|o. . +           |

|. .              |

|                 |

+-----------------+


2. Теперь надо "дать знать" ssh ваш общественный ключ, путем копирования его на сервер:

scp  ~/.ssh/id_rsa.pub username@hostname: ~/.ssh/authorized_keys



3. Защищаем ssh директорию от несанкционированного доступа другими лицами:

user1@host1:~$ chmod -R go-rwx .ssh/

user1@host1:~$ ls -la .ssh

total 20

drwx------ 2 user1 user1 4096 2010-06-09 15:33 .

drwxr-xr-x 4 user1 user1 4096 2010-06-09 15:22 ..

-rw------- 1 user1 user1 393  2010-06-09 15:33 authorized_keys

-rw------- 1 user1 user1 1675 2010-06-09 15:22 id_rsa

-rw------- 1 user1 user1 393  2010-06-09 15:22 id_rsa.pub


4. Перегружаем ssh:

/etc/init.d/ssh restart


Настройка ssh на хосте.

Клиент:

Конфигурация клиента находится в /etc/ssh/ssh_config. Рекомендуется изменить строку 'Protocol' на 'Protocol 2' в связи с вопросами безопасности:
Protocol 2

 

Сервер:

Конфигурация SSH демона находится в /etc/ssh/sshd_config.
Выключаем SSH соединения для ipv6 (если это не нужно):
#AddressFamily any # default
AddressFamily inet # IPv4 only
#AddressFamily inet6 # IPv6 only
Разрешаем коннектиться только определенным пользователям:
AllowUsers userA userB
AllowGroups sshusers
Отключаем root login:
PermitRootLogin no
Выставляем log out timeout interval (в секундах):
# Sets a timeout interval in seconds after which if no data has
# been received from the client, sshd will send a message through
# the encrypted channel to request a response from the client.  The
# default is 0, indicating that these messages will not be sent to
# the client.
ClientAliveInterval 300

# Sets the   number of client alive messages (see above) which may be sent
# without sshd receiving any messages back from the client.  If this
# threshold is reached while client alive messages are being sent, sshd
# will disconnect the client, terminating the session.
ClientAliveCountMax 0

 

Защита сервера:

Чтобы разрешить соединения. Надо отредактировать /etc/hosts.allow:
# let everyone connect to you
sshd: ALL
# OR you can restrict it to a certain ip
sshd: 192.168.0.1
# OR restrict for an IP range
sshd: 10.0.0.0/255.255.255.0
# OR restrict for an IP match
sshd: 192.168.1.
Для всех остальных – запрещаем: /etc/hosts.deny:
ALL: ALL: DENY


Перезагрузка sshd:
/etc/init.d/ssh restart

Если планируется запуск тонких клиентов, то ничего вносить не нужно в /etc/hosts.allow и etc/hosts.deny.