How to change your SSH port

Step 1 – Connect to your server using SSH. If you are using Windows you can use the program Putty or if you are using iOS simply use the terminal.


Step 2 – Now find the below line in the sshd_config file:


This line indicates which port you are using for SSH.

Step 3 – Remove the # symbol to uncomment the line. This can be done by hitting the X key whilst the cursor is over the # symbol. Edit the number “22” to your desired port value, the valid range for the port is 0 to 65535. Press ESC and type :wq, this exits you out from edit mode.
W stands for write and Q for quit. In this example i have chosen to use port 57343.


Step 4 – Now we need to update the firewall rules. Enter the command below.


Step 5 – Save the new settings using the command below


Step 6 – We need to test whether our new SSH port working or not. But before that disable the firewall temporarily.





Step 7 – Type the following command to reload SSHD service:


Step 8 – You can verify the new port settings using the command below.


Step 9 – If we see that the new port is working fine, we will start firewall using the commands:





Step 10 – Without closing this session, try and connect using your new port. If you are successful then please enter the below command to drop port 22 from the SSH access list.


Ready for a more resilient infrastructure?

Stop settling for slow support and generic security. Get a free, no-obligation Security & Cloud Audit from our Manchester-based engineers.

Ready for a more resilient infrastructure?

Stop settling for slow support and generic security. Get a free, no-obligation Security & Cloud Audit from our Manchester-based engineers.

Ready for a more resilient infrastructure?

Stop settling for slow support and generic security. Get a free, no-obligation Security & Cloud Audit from our Manchester-based engineers.