Connecting to an SSH server on a port other than 22 is necessary whenever the remote sshd listener is bound to a different TCP port. Using the correct port determines whether the client reaches the login prompt or stops with a network error before authentication begins.
The OpenSSH client connects to port 22 by default. The -p option overrides that default for one connection, while the Port directive in ~/.ssh/config stores the alternate port in a reusable host alias that can later be inspected with ssh -G.
This workflow assumes the server is already listening on the alternate port and that any firewall or NAT rule in the path allows the connection. The first connection to that endpoint can still prompt for host-key confirmation, and using the wrong port usually ends with Connection refused, Connection timed out, or no login prompt at all.
$ ssh -p 2222 user@host.example.net whoami user
Omit the trailing whoami to open a normal interactive shell instead of running a one-command login test.
If the client returns Connection refused or waits until a timeout, the server may not be listening on that port or the network path to it is still filtered.
Host host-alt-port
HostName host.example.net
User user
Port 2222
Add IdentityFile only when that host requires a non-default private key.
$ ssh host-alt-port whoami user
The same alias can also be reused with scp and sftp so those commands inherit the configured port automatically.
$ ssh -G host-alt-port host host-alt-port user user hostname host.example.net port 2222 ##### snipped #####
ssh -G prints the final client settings after the matching Host blocks and built-in defaults are applied.
Related: How to show SSH client configuration