github icon
github icon

shafikshaon / Connect to Ubuntu Server on VirtualBox via SSH

Created Sat, 19 Oct 2019 02:47:09 +0600 Modified Wed, 17 Jul 2024 08:21:53 +0000
259 Words 2 min

Here, I guide how to connect with ubuntu server installed on virtual box via SSH.

Install Virtual box and Ubuntu Server

Download virtual box from Oracle Virtualbox.

Install virtual box on your machine.

Download ubuntu server from ubuntu.

Then setup ubuntu server on virtual box.

After successful setup, login to ubuntu server in virtual machine.

Setup SSH on ubuntu server

Then open terminal and install following packages:

sudo apt update
sudo apt install openssh-server
sudo apt install ssh

Once installation is completed, the SSH service should start automatically. To verify the installation type following command:

sudo systemctl status ssh

You should see something like Active: active (running)

Now go to virtual box click on ubuntu instance and click on settings. Then click on Network Then choose Adapter 1 select Attached to to Bridge Adapter and Name to anyone.

Then run following command in ubuntu server.

sudo ufw disable

Login to server via SSH

Then login to server via ssh by following command

ssh your_username@your_server_ip_address

To see ip address type following command


In my case, ip address is and username is test


If you get timeout while connecting via ssh.

Stop your virtual machine. Set the net of your virtual machine: Click on settings and network: Select NAT as connection and click on advanced.

Click on port forwarding:

Name: SSH
Protocol: TCP
Host IP:
Host Port: 2222
IP Guest: Empty
Port Guest: 22

Start your Virtual Machine: When your virtual machine is started, open your terminal and try to connect:

ssh [email protected] -p 2222
Commit ID: c5d17ea267e3042c327c7fa17af122cf4c614f7b ∙ View Commit on GitHub