Но вариантов установки порта я так понимаю несколько, ручной, какой-то рандомный и с еще дополнительными хитростями.
К примеру в руководстве по ssh в wiki есть такой вариант.
Добавить в rc.local следующий скрипт rc.ssh_hide:
Код: Выделить всё
#!/bin/bash
######First, set SSHD back to the default port 22.
######Next, figure out what port or ports you want to do SSH over.
######Were going to use 99, 88, and 8889 here.
######Now we take care of the Hypothetical Evil Unprivileged User
######by not accepting anything over those ports in the first place.
######This is only effective for port 8889 but well do all three ports for the sake of completeness.
/usr/sbin/iptables -t filter -A INPUT -p tcp -m multiport --dports 99,88,8889 -j REJECT --reject-with tcp-reset
######Then, pick a number between 1 and 4294967295 Ill use 0x13F ()
######Were going to tell iptables to reject anything without this mark coming into port 22.
/usr/sbin/iptables -t filter -A INPUT -p tcp -m tcp --dport 22 -m connmark ! --mark 0x13F -j REJECT --reject-with tcp-reset
######Now well tell iptables what ports we will accept for ssh.
/usr/sbin/iptables -t filter -A FORWARD -p tcp -m multiport --dports 99,88,8889 -j ACCEPT
######In the mangle table we slap our mark on these packets.
/usr/sbin/iptables -t mangle -A PREROUTING -p tcp -m multiport --dports 99,88,8889 -j CONNMARK --set-mark 0x13F
######Finally in the nat table we tell iptables to send the marked packets back to port 22
/usr/sbin/iptables -t nat -A PREROUTING -p tcp -m multiport --dport 99,88,8889 -j REDIRECT --to-ports 22
exit 0
Но я не могу понять это хороший способ или плохой и достаточно просто руками указать не стандартный порт и не заморачиваться. Хотелось бы узнать что более опытные пользователи думают на счет этого и как поступают для обеспечения безопасности ssh.What it is doing is making it look like you changed the port ssh is using and provide some additional security. What happens is scanners will continue to see port 22 open and try to go there while your server drops those packets, because the header is not mangled. Real packets come in on port 8889 and are redirected by iptables to port 22 with mangle in the header so they don't get dropped.