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 an experienced cloud architect with a strong development and open-source advocacy background. He boasts multiple certifications in AWS, Red Hat, VMware, ITIL, and Linux, underscoring his expertise in cloud architecture and system administration.
Mohd Shakir Zakaria is an experienced cloud architect with a strong development and open-source advocacy background. He boasts multiple certifications in AWS, Red Hat, VMware, ITIL, and Linux, underscoring his expertise in cloud architecture and system administration.
Discuss the article:
Comment anonymously. Login not required.