SSH servers typically use port 22 by default. However, there are times when connecting through a different port is required. This might be due to security policies, server configurations, or specific network requirements.

To connect to an SSH server on a non-standard port, the port number must be specified during the connection process. This can be done using the -p option in the command line or by configuring the port in the SSH client’s configuration file.

Specifying a port other than the default ensures that the SSH client connects to the correct service. This approach is essential for accessing servers that are not listening on port 22.

Steps to connect to SSH server on custom port:

  1. Identify the port number that the SSH server is using.
  2. Verify that the client can reach the server's specified port.
    $ 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.
  3. Specify the port number when connecting to the server.
    $ ssh remoteuser@remotehost -p 2022
  4. Optionally, add the port configuration to the SSH client's configuration file.
    $ cat .ssh/config
    Host remotehost
        hostname 192.168.1.10
        user remoteuser
        port 2022
  5. Connect to the server using the specified host name.
    $ ssh remotehost
Discuss the article:

Comment anonymously. Login not required.