ssh is the default protocol used to manage remote systems which are mainly Linux and Network Devices. As it is working over a network connection and uses TCP it has a default port number which is 22. In this tutorial, we will look at how to change the default port number from the client and server point of view.
List SSH Server Port Configuration
Linux ssh server configuration is stored in
/etc/ssh folder with a name
sshd_config . This configuration file provides a lot of configuration parameters. We can print the current port configuration with the following command by grepping
$ cat /etc/ssh/sshd_config | grep Port
Change SSH Server Port Configuration
In order to change port configuration we just need to remove the
# from begging of the configuration line with is listed in the previous step. So
will change to the below where number is the port number we want.
and We need to restart the
ssh service in order to affect changes.
$ sudo systemctl restart ssh
Change SSH Client Port Configuration
Now we have changes
ssh port of the server but how can we specify different port than
22 in ssh client. We use a Linux ssh client which uses port 22 as default. We will use -p option in order to specify the port number we want to connect. In this example, we will connect to the port number
$ ssh -p 2222 192.168.1.1