Share your love
SSH Port Number Change on Debian
This tutorial intends to teach you to Change the SSH Port Number on the Debian Server. SSH Port is used for secure remote login from one computer to another. The default SSH port is port 22. It is recommended to change this port for security reasons.
In this tutorial we use Debian 12 Bookworm to change our SSH port, you also can use Debian 10 or Debian 11.
Now follow the steps below to complete this guide.
SSH Port Number Change on Debian
To complete this guide, you must have access to your server as a root or non-root user with sudo privileges. To do this, you can check the following Debian initials guides:
Initial Server Setup with Debian 10
Initial Server Setup with Debian 11
And Initial Server Setup with Debian 12 Bookworm
Step 1 – Check the Current SSH Configuration on Debian
The first step is to check your current SSH port on your Debian server. To do this, you can run the command below in your Debian terminal:
sudo grep -i port /etc/ssh/sshd_config
In my case, I get the following output:
Output
Port 22
Step 2 – Edit the sshd_config File To Change SSH Port
At this point, you must edit the sshd_config file to change your SSH port. Open the file with your desired text editor, we use vi:
sudo vi /etc/ssh/sshd_config
Find the Port 22 line and change its value to the desired number that you want to use for your SSH port. Here we use port 3823.
Port 3823
When you are done, save and close the file.
Every time you make configuration changes to this file, you must restart SSH to apply the changes. To do this, run the command below:
sudo systemctl restart sshd
Step 3 – Verify the New SSH Port on the Debian
At this point, run the netstat command and make sure that the ssh daemon now listens on the new ssh port:
sudo netstat -pnltu | grep ssh
In your output, you should see that your SSH port is listening on the new SSH port:
Output
tcp 0 0 0.0.0.0:3823 0.0.0.0:* LISTEN 88540/sshd: /usr/sb
tcp6 0 0 :::3823 :::* LISTEN 88540/sshd: /usr/sb
Step 4 – Allow SSh port on Debian UFW Firewall
Now if you have a running UFW firewall, you must allow the new SSH port. To do this, run the following command:
sudo ufw allow 3823/tcp
Then, reload the firewall to apply the new rules:
sudo ufw reload
Step 5 – Login To Debian with New SSH port
At this point, you can exit from your server and use your new SSH port to log in to your server:
ssh –p 3823 linuxuser@server-ip-address
Is it possible to change the SSH port in Linux?
Definitely Yes. Always it is recommended to change the SSH port number to increase your security. As you can see in the above steps, you can easily change the default SSH port number on Debian Linux.
Conclusion
At this point, you have learned to increase your server security by changing the default SSH port number which is port 22 on Debian. To do this, you have learned to edit the ssh_config file and change your default SSH port.
Hope you enjoy it.