Чек-лист: безопасная настройка OpenSSH
Чек-лист: безопасная настройка OpenSSH
Введение
OpenSSH — основной протокол удалённого администрирования. Ошибки в конфигурации приводят к компрометации узлов. Данный чек-лист покрывает криптографию, аутентификацию и аудит.
Криптография
- Использовать только ed25519 ключи:
ssh-keygen -t ed25519 -a 100 - Запретить RSA/DSA в
PubkeyAcceptedAlgorithms:ssh-ed25519-cert-v01@openssh.com,ssh-ed25519 - Включить только современные шифры в
Ciphers:chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.com - MACs:
umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com - Kex:
curve25519-sha256,curve25519-sha256@libssh.org,diffie-hellman-group-exchange-sha256
Аутентификация
-
PasswordAuthentication no -
KbdInteractiveAuthentication no -
PermitRootLogin prohibit-password(илиno) -
AllowUsers/AllowGroups— белый список -
PubkeyAuthentication yes -
AuthorizedKeysFile .ssh/authorized_keys -
AuthenticationMethods publickey
Ограничения
-
ClientAliveInterval 300 -
ClientAliveCountMax 2 -
MaxAuthTries 3 -
LoginGraceTime 30 -
PermitEmptyPasswords no -
PermitUserEnvironment no -
X11Forwarding no -
AllowTcpForwarding no(или точечно) -
GatewayPorts no
Аудит и харднинг
-
LogLevel VERBOSE -
SyslogFacility AUTH -
UseDNS no -
StrictModes yes -
Compression delayed -
Banner /etc/issue.net
Пример /etc/ssh/sshd_config
Port 22
Protocol 2
HostKey /etc/ssh/ssh_host_ed25519_key
Ciphers chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.com
KexAlgorithms curve25519-sha256,curve25519-sha256@libssh.org
MACs umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com
PubkeyAcceptedAlgorithms ssh-ed25519-cert-v01@openssh.com,ssh-ed25519
PasswordAuthentication no
KbdInteractiveAuthentication no
PermitRootLogin prohibit-password
AllowUsers admin
PubkeyAuthentication yes
AuthenticationMethods publickey
ClientAliveInterval 300
ClientAliveCountMax 2
MaxAuthTries 3
LoginGraceTime 30
PermitEmptyPasswords no
PermitUserEnvironment no
X11Forwarding no
AllowTcpForwarding no
GatewayPorts no
LogLevel VERBOSE
SyslogFacility AUTH
UseDNS no
StrictModes yes
Compression delayed
Чек-лист деплоя
- Ключи сгенерированы на клиенте, публичные добавлены через AWX/Ansible
- Старые host keys отозваны
- Fail2ban настроен на ssh
- Конфигурация проверена:
sshd -t - ] Сервис перезагружен:
systemctl reload sshd
Заключение
Следование этому чек-листу закрывает 95% векторов атак на SSH. Оставшиеся 5% — дисциплина обновлений и мониторинг.