In this article, we will delve into the process of changing the default Secure Shell (SSH) port on your server. SSH is a protocol that enables secure remote access to and management of your server. It is crucial to modify the SSH port in order to boost security because the default port is well known and commonly targeted by bad actors.
You may significantly lower the risk of successful assaults on your server by changing the default SSH port. We’ll take you step-by-step through the procedure in this article, which includes modifying the SSH configuration file and upgrading firewall rules. Whether you are a seasoned system administrator or are just getting started, this article will give you the knowledge you need to confidently modify your SSH port.
Let’s get started!
Here is a step-by-step guide to change the default SSH port in a Debian VPSie operating system:
Log in to your Debian server as the root user or a user with root privileges. Open the SSH configuration file using a text editor, such as nano, by running the following command:
Find the line that specifies the default SSH port (usually Port 22) and change it to the desired port number. For example, if you want to change the SSH port to 2233, the line would look like this:
Save the changes and exit the text editor.
Restart the SSH service for the changes to take effect. Run the following command:
systemctl restart ssh
Update the firewall rules to allow incoming connections on the new SSH port. You can do this using iptables by running the following command:
iptables -A INPUT -p tcp --dport 2233 -j ACCEPT
If you receive the error message iptables: command not found. it means that the iptables package is not installed on your system. To install iptables on a Debian-based system, you can use the following command:
sudo apt-get install iptables
This will install the iptables package and its dependencies. After installation, you should be able to run the iptables command and check the status of your iptables firewall.
Note: Replace 2222 with the new SSH port number you specified in above step.
To make the firewall changes permanent, you’ll need to save them to the firewall configuration file. You can do this by using the iptables-persistent package:
apt-get install iptables-persistent
Test the new SSH port by attempting to connect to the server using the new port number. You can use the following command:
ssh user@your-server-ip -p 2233
Note: Replace user with your username, and your-server-ip with the IP address of your server.
That’s it! You have successfully changed the default SSH port in your Debian operating system.