How To Change OpenSSH SSH Server Port Number In Linux? – POFTUT

How To Change OpenSSH SSH Server Port Number In Linux?


Remote access is the main method while managing Linux systems. Remote access must be secured accordingly. OpenSSH suite which implements Ssh provides this security with server and client side. OpenSSH also provides auxiliary tools to make copying or identity management easily and securely. OpenSSH servers run by default TCP port 22. We call it generally ssh port. Ssh port number is know for the whole world so attackers can attack to beat our OpenSSH server like brute forcing.

Get Ssh Server Port Number From Ssh Configuration

Ssh server configuration file can be found at /etc/ssh/sshd_config . We will find related configuration line like below.

$ grep Port /etc/ssh/sshd_config  
#Port 22 
#GatewayPorts no 


$grep Listen /etc/ssh/sshd_config      
#ListenAddress 0.0.0.0 
#ListenAddress ::
Get Ssh Server Port Number From Ssh Configuration
Get Ssh Server Port Number From Ssh Configuration

We can see that default configuration is used for ports because they are commented.

Change Ssh Server Port Number

We will open configuration file and add line below

Port 2134

Keep in mind be sure there is no other application using this port.

Restart Ssh Server To Apply Configuration

We have changed the configuration but in order to make the new configuration effective we need to restart the SSH service. During restart the SSH service will read its configuration where the new port is  2134 is listening.

$ sudo systemctl restart sshd

Check New Port

There are different ways to check new SSH port. In this example we will use netstat command with the options -tln which means list TCP ports listening.

$ netstat -tln | grep 2134
tcp        0      0 0.0.0.0:2134              0.0.0.0:*               LISTEN      
tcp6       0      0 :::2134                   :::*                    LISTEN

Connect Ssh With Different Port Number

By default while using ssh command we do not provide the port number 22 explicitly. ssh command assumes the port number 22. But what if we need to connect ssh server which port is different than 22. We will specify port number with -p option. In this example we will connect port number 2134

$ ssh -p 2134 poftut.com

How To Change OpenSSH SSH Server Port Number In Linux? Infografic

 How To Change OpenSSH SSH Server Port Number In Linux? Infografic
How To Change OpenSSH SSH Server Port Number In Linux? Infografic

 

LEARN MORE  How To Use mRemoteNG For RDP, VNC, SSH Remote Connections?

Leave a Comment