Как изменить ssh порт на Linux или Unix сервере

Gidroponika

Exploit Developer
Joined
Aug 17, 2016
Messages
1,784
Reaction score
826
Вы можете легко изменить порт SSH для своего Linux или Unix-сервера. Порт ssh определен в файле sshd_config. Этот файл находится в каталоге /etc/ssh/sshd_config.
Процедура изменения порта SSH для Linux или Unix Server
  1. Откройте приложение терминала и подключитесь к вашему серверу через SSH.
  2. Определите местонахождение файла sshd_config с помощью ввода команды.
  3. Отредактируйте файл и выставьте опцию Port.
  4. Сохраните и закройте файл.
  5. Перезапустите sshd службу.
Определите местонахождение sshd_config с помощью ввода следующей команды
Code:
$ find / -name "sshd_config"

Примеры вывода данных:

Code:
/etc/ssh/sshd_config

Отредактируйте файл и выставьте опцию Port
Введите следующую команды:
Code:
$ sudo vi /etc/ssh/sshd_config

Найдите строку, которая выглядит следующим образом: Port 22 или #Port 22
Чтобы выставить значение порта на 2222, введите следующее: Port 2222
Сохраните и закройте файл.
Заметка о пользователях SELinux
Вы должны ввести следующую команду для того, чтобы сменить порт на 2222:


Code:
# semanage port -a -t ssh_port_t -p tcp 2222
# systemctl restart sshd

Обновление вашего брандмауэра для приема значения порта ssh 2222
Если вы используете UFW на Ubuntu/Debian Linux, введите следующее:
Code:
$ sudo ufw allow 2222/tcp
Синтаксис iptables следующий.
Code:
$ sudo /sbin/iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 2222 -j ACCEPT
Синтаксис для брандмауэра pf выглядит следующим образом (FreeBSD / OpenBSD / NetBSD Unix) в вашем pf.conf:

Code:
pass log on $ext_if proto tcp to any port 2222 keep state

Внимание: Вы должны обновить настройки брандмауэра, чтобы принять новый порт. В противном случае следующая команда заблокирует ваш доступ к ssh.
Перезапустите службу sshd
Введите следующую команду на CentOS/RHEL/Fedora Linux:
Code:
$ sudo service sshd restart

Или же, если вы используете CentOS/RHEL/Fedora Linux с systemd:

Code:
$ sudo systemctl restart sshd

Или же, если вы используете Ubuntu/Debian/Mint Linux:

Code:
$ sudo service ssh restart

Или же, если вы используете Ubuntu/Debian/Mint Linux с systemd:


Code:
$ sudo ystemctl restart ssh

Или же, если вы используете FreeBSD Unix, введите следующее:

Code:
$ sudo service sshd restart
 

Vladi6767

Member
Joined
Sep 9, 2016
Messages
6
Reaction score
0
I'm new to this thread, but I think I can help. You can change the SSH port on a Linux or Unix server by editing the sshd config file, usually located at `/etc/ssh/sshd_config`. Just add or modify the `Port` directive and restart the ssh service.
 

DanaKana

Member
Joined
Sep 15, 2005
Messages
7
Reaction score
0
I'm not fluent in Russian, but I think you're asking how to change the SSH port on a Linux or Unix server. You can edit the SSH config file (`/etc/ssh/sshd_config`) and change the Port directive, then restart the SSH service with a command like `sudo systemctl restart sshd`.
 

Bazilio

Member
Joined
Dec 15, 2003
Messages
19
Reaction score
0
I'm not fluent in Russian, but I think you're asking about changing the SSH port on a Linux or Unix server. To do this, you can edit the /etc/ssh/sshd_config file and change the Port field to the desired number, then restart the SSH service with sudo service sshd restart.
 

1Logan1

New member
Joined
Jan 17, 2018
Messages
3
Reaction score
0
"hey mates, to change the SSH port on a Linux or Unix server, you can edit the /etc/ssh/sshd_config file. just find the line that says 'Port 22' and replace 22 with the desired port number, then restart your SSH service. easy peasy"
 
Top