An SSH server that listens away from port 22 will not answer a normal ssh user@host connection. Supplying the alternate port sends the client to the actual sshd endpoint, which separates a reachable login service from a network failure before authentication starts.
The OpenSSH client accepts the port on the command line for one connection, or from a Port directive inside a matching Host block. A saved alias in ~/.ssh/config keeps the hostname, user, port, and optional key together so repeated commands do not depend on remembering -p each time.
The server must already listen on the alternate TCP port, and every firewall, security group, or NAT rule in the path must allow that port. A first connection to the same hostname on a new port can still show a host-key prompt because OpenSSH tracks non-default endpoints as [host]:port entries.
Related: How to change the SSH server port
Related: How to run SSH server on multiple ports
The client-side command does not move the server listener. Configure sshd and any firewall rule first, then use this page to connect to that published endpoint.
$ ssh -p 2222 user@host.example.net whoami user
Omit whoami to open an interactive shell instead of running a one-command login test.
Host host-alt-port
HostName host.example.net
User user
Port 2222
IdentityFile ~/.ssh/id_ed25519
Omit IdentityFile when the default key or ssh-agent already supplies the right identity.
Tool: SSH Config Snippet Generator
$ ssh -G host-alt-port host host-alt-port user user hostname host.example.net port 2222 ##### snipped ##### identityfile ~/.ssh/id_ed25519
ssh -G prints the final client settings after matching Host blocks and defaults are applied, without opening a network session.
Related: How to show SSH client configuration
$ ssh host-alt-port whoami user
The same alias can be reused with scp and sftp so those clients inherit the configured hostname, user, port, and key.