Изменение порта SSH
Пошаговое руководство по изменению порта SSH
Изменение порта необходимо, так как если оставить значение по умолчанию, потенциальным злоумышленникам будет проще найти возможность подключиться к серверу.
Откройте файл / etc / ssh / sshd_config в текстовом редакторе (редактор не важен, в данном примере мы используем nano)
# nano /etc/ssh/sshd_config
Откомментируйте строку #Port 22 и измените значение на желаемое
# $OpenBSD: sshd_config,v 1.93 2014/01/10 05:59:19 djm Exp $
# This is the sshd server system-wide configuration file. See
# sshd_config(5) for more information.
# This sshd was compiled with PATH=/usr/local/bin:/usr/bin
# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented. Uncommented options override the
# default value.
# If you want to change the port on a SELinux system, you have to tell
# SELinux about this change.
# semanage port -a -t ssh_port_t -p tcp #PORTNUMBER
#
#Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::
# This is the sshd server system-wide configuration file. See
# sshd_config(5) for more information.
# This sshd was compiled with PATH=/usr/local/bin:/usr/bin
# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented. Uncommented options override the
# default value.
# If you want to change the port on a SELinux system, you have to tell
# SELinux about this change.
# semanage port -a -t ssh_port_t -p tcp #PORTNUMBER
#
#Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::
Далее, в зависимости от брандмауэра, работающего в системе, создаем правило, согласно которому соединения с новым портом не будут запрещены
Для iptables:
#iptables -I INPUT -s 0.0.0.0/0 -p tcp -m tcp --dport [new port number] -j ACCEPT
#iptables-save
#iptables-save
для брандмауэра
# firewall-cmd --permanent --zone=public --add-port=2234/tcp
# firewall-cmd --reload
# firewall-cmd --reload
После этого можно перезапустить службу SSH
# service sshd restart
При перезапуске службы соединение будет разорвано. Далее, при подключении к серверу необходимо указать номер порта, например
$ ssh root@111.222.223.224 -p 22777