How Can I Change My SSH Port: A Simple Guide
SSH or Secure Shell refers to a network communication protocol that can be used to access a computer securely over an unsecured network. Apart from providing secure access, network administrators commonly use SSH to manage applications and systems remotely.
SSH protocol can also be used for other purposes such as for transferring files between machines remotely and securely, creating secured TCP tunnels over it, etc.
It’s always a good idea to change the default SSH port because it’s frequently targeted by automated bots and hackers for vulnerabilities. Now, if you’re thinking “how can I change my SSH port,” this guide is here to help.
Before we delve deeper into the process of how to change the SSH server port number, you should note that this isn’t a concrete solution that can protect your SSH service from getting attacked by a knowledgeable hacker.
It’s just a measure to protect your SSH service from hackers and automated bots continuously scanning the IP space searching for default SSH ports being open.
The default SSH port is 22. Since provides full access to the OS of your server, hackers frequently target it more than any other port. By changing the default SSH port you can prevent automated attacks that don’t have the time to check other ports when attacking a Linux server.
Let’s see the answer to your primary question, “how can I change my SSH port.”
How to Change the SSH Server Port Number?
The prerequisite for the process of how to change the SSH port on Linux is having root access to your Linux server.
Here’re the steps involved in the process of how to change the SSH server port number.
Step #1: Connect Using SSH
First, you need to log in to your Linux server via SSH using your root access privileges. This can be done by entering the following command.
sshroot@Server_IP_Address -p Port_Number
In case you aren’t using the root user, be sure to type your username in the place of “root.” Additionally, replace, Port_Number and Server_IP_Address with your actual SSH port number and IP address. If you’ve never modified the port number, this should be 22.
This was the first step in the answer to your question, “how can I change my SSH port.” Let’s proceed to the subsequent step.
Step #2: Choose a New Port Number
Prior to modifying the default SSH port, you need to choose a new port for the SSH to listen on. You can choose any unused port. When it comes to Linux, port numbers lower than 1024 are used by well-known services and hence, can be discovered more easily. Therefore, it’s advisable to choose a port number higher than 1024. The maximum port number that you can setup for SSH is 65535.
In this guide, we’ll change the default SSH port number to 34627.
Step #3: Configure Your Firewall
Before you change the default SSH port, you need to configure your firewall on the server so that traffic can be allowed on your new SSH port.
If you’re using a Fedora/RHEL/CentOS-based operating system, your new SSH port 34627 can be opened with the “firewall-cmd” command.
firewall-cmd –permanent –zone=public –add-port=34627/tcp
If you’re using a Debian/Ubuntu-based operating system, your new port 34627 can be opened with the “ufw” command.
ufw allow 34627/tcp
Once this is done, your server can allow traffic on your new SSH port.
Step #4: Modify the Default SSH Port
The default SSH port can be modified by editing the “/etc/ssh/sshd_config” file.
Look for the following line:
# Port 22
Eliminate the pound symbol “#” to uncomment the line and replace it with this line:
When you’re done, save and close the file. Then, you need to restart the SSH service so that the changes can be applied. Use the following command to do it.
systemct| restart ssh
Now, you need to verify the new SSH listening port using the following command:
netstat -plntu | grep34627
If you’ve correctly completed all the steps of how to change the SSH server port number that we’ve discussed so far, the below output should be seen on your screen.
tcp 0 0 0.0.0.0:34627 0.0.0.0:* LISTEN 1722/sshd
tcp6 0 0 :::34627 :::* LISTEN 1722/sshd
Step #5: Connect To SSH Via the New Port
Now, you need to log out from your present SSH session and reconnect your server using the new port.
ssh -p 34627 root@Server_IP_Address
If there’s no issue, you should be able to connect to your server and receive a password prompt.
So, this was the answer to your question, “how can I change my SSH port.” Just follow these simple steps and you should be able to successfully change the default SSH port number on your Linux server.