DEV Community

Mohd. Shafikur Rahman
Mohd. Shafikur Rahman

Posted on • Updated on

Ubuntu Server setup on Virtual box and connect with SSH

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 a 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
Enter fullscreen mode Exit fullscreen mode

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

sudo systemctl status ssh
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Login to server via SSH

Then login to server via ssh by following command

ssh your_username@your_server_ip_address
Enter fullscreen mode Exit fullscreen mode

To see ip address type following command

ifconfig
Enter fullscreen mode Exit fullscreen mode

In my case, ip address is 192.68.31.225 and username is test

ssh test@192.68.31.225
Enter fullscreen mode Exit fullscreen mode

Optional

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: 127.0.0.1
Host Port: 2222
IP Guest: Empty
Port Guest: 22
Enter fullscreen mode Exit fullscreen mode

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

ssh yourusername@127.0.0.1 -p 2222
Enter fullscreen mode Exit fullscreen mode

Originally posted on https://shafik.xyz/posts/ubuntu-server-setup-on-virtual-box-and-connect-with-ssh/

Top comments (1)

Collapse
 
carllabuschagne profile image
Carl Labuschagne

Thank you, this is exactly what I needed. Easy to follow and got up and running in a couple of minutes. Now busy setting up docker containers.