How to connect to SSH server on alternate port
SSH server, by default, listens to port 22, and you don't have to manually specify the port number on your SSH client if you're connecting to the server's default port.
You can specify the port number when connecting to non-standard SSH ports using the -p option or adding the port information in your SSH client's configuration file.
Steps to connect to SSH server on ports other than 22:
Test if the port that the SSH server listens to is reachable from the client host.
$ nc -zv remotehost 2022 Connection to remotehost 2022 port [tcp/*] succeeded!
-v Produce more verbose output. -z Only scan for listening daemons, without sending any data to them. Cannot be used together with -l.
Specify port to connect to using -p option.
$ ssh [email protected] -p 2022
Add port configuration to SSH client configuration file for persistence.
$ cat .ssh/config Host remotehost hostname 192.168.1.10 user remoteuser port 2022
Connect again using SSH client with just the Host name without having to provide port number as parameter.
$ ssh remotehost