[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More


How to Configure SSh to authenticate to different Port and Allow acces through the Firewall Ubuntu

Published on
23,907 Points
Last Modified:
This article will explain how to establish a SSH connection to Ubuntu through the firewall and using a different port other then 22. I have set up a Ubuntu virtual machine in Virtualbox and I am running a Windows 7 workstation.

From the Ubuntu virtual machine open the Terminal:


First you will need to install the SSH:

sudo apt-get install openssh-server

Open in new window

Will change the connection port:

sudo gedit /etc/ssh/sshd_config

Open in new window

Now save the file.

Under #What ports, IPs and protocols we listen for
Port  56628  

Since I configure this already I am providing the screenshot of the sshd_config file by using the grep command -A1 tells grep to include 1 line after the match. -B1 includes lines before the match.
Sshd_Config File****I am using this port as an example.*****

In order for changes to take, you have to restart the ssh service.

sudo restart ssh

Open in new window

Check to see if the firewall is installed

dpkg --get-selections ufw

Open in new window

If it is then your output would look like this:

ufw                                            install
Check to see the ufw is installIf it is not installed perform this action:

sudo apt-get install ufw

Open in new window

Now enable the ufw:

sudo ufw enable

Open in new window

Next we are going to allow the workstation access to 56628 port from the IP address.

Press the windows key + r  and type cmd and press Enter.  This will bring up the command prompt.  Now type ipconfig /all and  locate the IP address of the workstation.

On the Ubuntu virtual machine from the Terminal type:

sudo ufw allow from <The IP address you just located on the windows workstation>  to any port 56628

sudo ufw allow from to any port 56628

Open in new window

Press enter and now you can see that entry in the firewall by typing

sudo ufw status

Open in new window

The  entry would look along the lines of this

Status: active

To                                                          Action                     From
 --                                                          ----------                    --------
56628                                                   ALLOW        

Here is my example of this status of the  firewall and the allowed ssh rule and Port.
Firewall Status and Allowed Port Number
Now find the IP address of the Ubuntu workstation from the terminal. Type


We are going to need to install Putty on the Windows workstation Here the link.  Once Putty is installed you need the IP address that you obtained from the Ubuntu virtual environment. Place it in the HostName and the Port 56628 in Port location.  Make sure SSH is selected and click open.  Once a connection is established you will be prompted for Username then your password.  Now you have made a successful SSH connection using a different port number then 22.

Input Information for Putty

Featured Post

Learn SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

Join & Write a Comment

How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Please check the video also in regards to recovery of deleted emails from office 365 admin center and through the MFCMAPI tool. I have mentioned each and every step with the proper steps that need to be taken care of.

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month