How to Change SSH Default Port in Linux

Introduction

SSH (Secure Shell) is a protocol used to securely connect to a remote computer. It uses an SSH port number, which is usually port 22, to establish the connection. This number is publicly known and can be used by malicious actors to gain access to your system if you don’t take the necessary security measures. That’s why it’s important to change the SSH port number in order to ensure that your system remains secure. In this article, we will discuss what an SSH port number is, how to change SSH Default Port in Linux and why you should consider changing it for better security.

Benefits of Changing Your SSH Port Number

Changing the default SSH port number is one of the most effective ways to secure your server against malicious attacks. By changing it, you can make sure that hackers and bots cannot easily detect your server and launch brute force attacks. This will give you an extra layer of security and help protect your data from unauthorized access.

Moreover, changing the default sshd port number also has other benefits such as improved performance, better reliability, and increased privacy. It can also help you save money on hosting costs since it reduces the load on the server by preventing unnecessary connections. All in all, changing your SSH port number is a great way to ensure enhanced security for your server.

Steps to Changing the Default SSH Port Number

Changing the default SSH port number is a critical step in securing your server from malicious attacks. By changing the port number, you can make it much harder for attackers to guess which port your SSH service is running on. In this article, we will discuss how to change the default SSH port number on Linux systems such as Ubuntu, CentOS, and Debian.

See also  What is SSH in Linux

1. Login to the server and open sshd configuration file :

# vi /etc/ssh/sshd_config

2. In this example, we’ll configure SSH service to bind and listen on port 2222/TCP.

#Port 22
Port 2222

Example :
How to Change SSH Default Port in Linux

3. Restart sshd service :

# systemctl restart sshd

4. Check the listen port for sshd service :

# netstat -plunt
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:2222              0.0.0.0:*               LISTEN      833/sshd
tcp6       0      0 :::2222                   :::*                    LISTEN      833/sshd
tcp6       0      0 :::33060                :::*                    LISTEN      920/mysqld
tcp6       0      0 :::3306                 :::*                    LISTEN      920/mysqld

Example :

Conclusion: Securing Your Network with a Different SSH Port Number

Securing your network with a different SSH port number is an important security measure that should not be overlooked. By changing the default port number of your SSH server, you can prevent hackers from easily scanning for open ports and gaining access to your network. Additionally, using a different port number can help you avoid the common attack vectors that are associated with the default SSH port. By taking these steps, you can ensure that your network remains secure and protected from malicious actors.

Leave a Comment