How to change the port when connecting via SSH.

To change the port when connecting via SSH, you need to run the following commands:
Ubuntu
Open the SSH configuration file in a text editor:
sudo nano /etc/ssh/sshd_config
We are looking for the line #Port 22, under it we will add the line (the port you need) Port 4000
We save and exit the configuration file (Ctrl+X) And
restart the ssh service:
sudo service sshd restart
We allow incoming SSH connections on the server:
sudo ufw allow ssh
Opening the port:
sudo ufw allow 4000
If you need to close the default port, run the following command:
sudo ufw deny 22

 

Centos
Installing a text editor:
yum install nano
Open the SSH configuration file in a text editor:
nano /etc/ssh/sshd_config
We are looking for the line #Port 22, under it we will add the line (the port you need) Port 1234
Installing policycoreutils-python to resolve the port:
yum install -y policycoreutils-python
Now you need to allow this port to connect via SSH:
semanage port-a-t ssh_port_t-p tcp 1234
The firewall is enabled by default in the CentOS 7 system. Therefore, you need to add a rule to it:
firewall-cmd --add-port=1234/tcp --permanent
And restart:
firewall-cmd --reload
Performing a reboot of the ssh service:
systemctl restart sshd

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

How to Install and Setup LAMP on CentOS VPS

LAMP (Linux - Apache - MySQL - PHP) is a common webserver software stack for Linux. Installing...

How to get a trial period VPS / VDS?

We provide a test server for a period of up to 1 day.To receive trial period VPS / VDS you need:...

How to install ionCube Loader on ISPmanager?

How to install ionCube Loader on ISPmanagerCheck OS version / x86_64 or x86$ uname -aDownload the...

Windows Server - Change the Administrator Password

Procedures for changing Administrator passwords This topic provides procedures to change...

Как получить пробный период VPS / VDS от Asvhost?

Как получить пробный период VPS / VDS? Мы предлагаем тестовый виртуальный сервер на срок от 1...