How to Connect to SSH on Different Port (Port other than 22)

How to Connect to SSH on Different Port (Port other than 22)

SSH runs on port 22 by default. When you get a new VPS, Cloud or Dedicated Server, the SSH service should be listening to port 22. It's recommended to configure the SSH to listen to a secret port. I will discuss how and why you should change your SSH Port on my other tutorials soon. In this tutorial we will be learning how to connect to SSH on different port.

SSH on Different Port

For security reasons most shared hosting providers who provide SSH access to their customers configure SSH to listen to a secret port. You need to ask your hosting provider for their SSH port if you get a connection refused error on your Terminal or SSH client. Or if you have changed the SSH port on your VPS, Cloud or Dedicated server and need to know how you can connect to SSH over the port that you configured, please follow the following instructions.

In my previous tutorials, to login to SSH I used the command ssh [email protected] on the terminal as I was running SSH service on my server on port 22. When you will be connecting to SSH through default port mentioning port number won't be necessary.

Let's assume your server's SSH service or your shared hosting provider's SSH service runs on port 2322. To connect to SSH over a non-standard port, open your Terminal App on Linux/Mac or PowerShell on Windows and type the following.

1ssh [email protected] -p PortNumber

Here -p flag specifies the port number of remote host. Remember to replace username with your username, with your server IP and PortNumber with your SSH port number. Here's an example.

1 ➜  ~ ssh [email protected] -p 2322
2[email protected]\'s password: 
3Last login: Sun Sep 11 01:30:41 2022 from
4[[email protected] ~]# 


As you have seen connecting to SSH through non-standard port doesn't require anything special except mentioning the port number with a -p flag.

This article is a part of a series.