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:
- Identify the port number that the SSH server is using.
- 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.
- Specify the port number when connecting to the server.
$ ssh remoteuser@remotehost -p 2022
- 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
- Connect to the server using the specified host name.
$ ssh remotehost

Author: Mohd
Shakir Zakaria
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.

Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.
Discuss the article:
Comment anonymously. Login not required.