While the standard port for SSH servers is 22, there are instances when it may be necessary to use an alternate port. This can be for security purposes or to accommodate other preferences or limitations.
There is no need to specify the port number if connecting to the default port. However, to connect to an SSH server on a custom port, you need to use the -p option or specify the port in the SSH client's configuration file.
$ 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.
$ ssh remoteuser@remotehost -p 2022
$ cat .ssh/config Host remotehost hostname 192.168.1.10 user remoteuser port 2022
$ ssh remotehost
Comment anonymously. Login not required.