While the standard port for SSH servers is 22, there are instances when it may be necessary to use an alternate port. This can be for security purposes or to accommodate other preferences or limitations.
There is no need to specify the port number if connecting to the default port. However, to connect to an SSH server on a custom port, you need to use the -p option or specify the port in the SSH client's configuration file.
Steps to connect to SSH server on ports other than 22:
- Determine the port the SSH server uses.
- Check if the client host can reach the server's listening port (optional).
$ 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.
- Use the -p option to specify the port when connecting.
$ ssh remoteuser@remotehost -p 2022
- Add the port directive to the SSH client configuration file for persistent connection option.
$ cat .ssh/config Host remotehost hostname 192.168.1.10 user remoteuser port 2022
- Connect again using the SSH client and the host name, without providing the port number as a parameter.
$ 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.