Skip to content
Home ยป How to Access the Server via SSH After Changing the SSH Port?

How to Access the Server via SSH After Changing the SSH Port?

The previous article explained how to change the SSH port. Nevertheless, after I changed the port, I could not access the server via SSH using the new port.

 

Problem

How to access the server via SSH after changing the SSH port?

 

Solution

Let’s say you have changed the SSH port from port 22 to port 43210 by changing it in the /etc/ssh/sshd_config file and checking the port by typing the command below:

sudo grep -E "^Port" /etc/ssh/sshd_config

 

After that, restart the SSH using the command below:

sudo systemctl restart sshd
resolve the issue after changing the port in SSH
Change to the new port in SSH

 

However, you can’t access the server via SSH using port 43210 but can still access via SSH port 22 as shown in the image below:

resolve the issue after changing the port in SSH
Test the result

 

In the remote, type the command below to check if the SSH port has changed to Port 43210 or not:

sudo ss -tulnp | grep sshd 

 

If you find the result as shown in the image below:

resolve the issue after changing the port in SSH
Check the port

 

It means the SSH is still connected to port 22 and not to port 43210. Therefore, type the commands below:

sudo systemctl stop ssh.socket
sudo systemctl disable ssh.socket
sudo systemctl mask ssh.socket
sudo systemctl restart sshd

 

Run the previous command to check the port:

sudo ss -tulnp | grep sshd
access the server via SSH
Check the port

 

You can see in the image above that the SSH port has changed to port 43210 and you should be able to access the server via SSH using port 43210.

access the server via SSH
Test the result

 

Note

The socket statistics, or ss, is a tool to display network socket information. This tool has the same function as netstat but has several advantages such as faster, filtering by connection state (e.g., established, time-wait), debugging high-performance networks, and so on.

 

References

askubuntu.com
rome-rohani.medium.com
discourse.ubuntu.com
community.clearlinux.org
redhat.com

image_pdfimage_print
Visited 11 times, 1 visit(s) today
Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *