ssh is default protocol used to manage remote systems which are mainly Linux and Network Devices. As it is working over network connection and uses TCP it has a default port number which is
22 . In this tutorial we will look how to change the default port number from client and server point of view.
List 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 current port configuration with the following command by grepping
$ cat /etc/ssh/sshd_config | grep Port
Change 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 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 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 Linux ssh client which uses port
22 as default. We will use
-p option in order to specify port number we want to connect. In this example we will connect to the port number
$ ssh -p 2222 192.168.1.1