How to change default SSH Port

How to change default SSH Port

The Linux server’s user can easily change the SSH port to other default port for secure server. You can change the SSH port follow the following steps

Step 1: Again Configure the SSHD:

For change the ssh port login as root into server via using the following command

ssh root@hostname/IP

you have to write your hostname at place of hostname and server’s IP address.

after login to server you can start the editing into file that is sshd _config. Before changing into config file you should be keep its backup.

Cp/etc/ssh/sshd_config /etc/ssh/sshd/_config_backup.

After taking the backup from sshd_config file you can edit into sshd_config file without any problem. For editing you need to open the sshd_config in any editor and use the vim that show the specified port line. When the ssh_config file will not be change then the port marked with symbol #.

Vim /etc/ssh/sshd_config

This symbol told to server for ignore that line. First you have to remove the symbol before change the port number 22 to another. Make sure you don’t use the same number that is used by any other services. If you check the port number that is used or not then you can check it in the list of number and their usages. After that use the port number that is not be used by any services. For instance we use the port number 2222 that is utilized by window.

For that delete the symbol # and modify the port number and then save the changes and exit from sshd_config file.

Step 2: Upgrading the firewall:

When we change the port number then we need to open that port in the firewall. We will describe the steps to changes in the firewall for standalone dedicated server. for updating your firewall we use the vim for changes. Before changes you should be keep the backup.

cp /etc/apf/cofig.apf /etc/apf/conf.apf.bak

you can open the /etc/apf/conf.apf into any editor. Then you will see the line Common ingress(inbound) TCP ports . After that you can add the new port with the ingress port. and save the changes and exit out from the conf.apf and close the editor.

Step 3: Again Start The Services:

For activate your changes you have to start the SSH and APF services again. For that you can apply the following command

/etc/init.d/apf restart

/etc/init.d/sshd restart

The ssh again start and listen at the new port number that you changed.
First release
Last update
0.00 star(s) 0 ratings