Easy way to SSH into VirtualBox machine | Any OS
Tags: ubuntu, linux, codenewbie, tutorial
Published: 2020-07-12 01:01:51

Hey there!
    This is [Tharun](https://www.tharunshiv.com) here. Most of us would have struggled to SSH into a VirtualBox Machine. In this article, I introduce to you what Virtual Box is and how you can SSH into it from your local machine.

## What is VirtualBox?

The [VirtualBox](https://www.virtualbox.org/) is a software that can be used to run multiple operating systems on your own operating system and effortlessly switch between them, create snapshots, delete them, restore them on the fly.

We all have wondered if we had an easier way to access our VirtualBox Machines. In this tutorial, we will look at how you can SSH into your VirtualBox machine. This will prevent you to have to open your VirtualBox GUI to do everything. (duh!)

### Did you know you could do this??

{% post https://dev.to/developertharun/launch-a-virtualbox-machine-without-gui-use-only-with-ssh-any-os-4m13 %}

## How to SSH into it?

### Open VirtualBox

![VirtualBox](https://dev-to-uploads.s3.amazonaws.com/i/5cp4f4sd1scms1fji5cv.png)

### Click on Settings and go to Network

You can either click on the Settings icon, or you can right-click on a Virtual Machine and select the Settings option

![network-virtualbox](https://dev-to-uploads.s3.amazonaws.com/i/y8orlayuzzo5c6cctg5v.png)

### Choose an Adapter

Based on which Adapter is free on your virtual machine. **Enable the Network Adapter.** Select the **NAT** network.

![NAT-virtualbox](https://dev-to-uploads.s3.amazonaws.com/i/v9dznpwvm6sarsiz97df.png)

### Select the Port Forwarding

Open the **Advanced** options and click on **Port Forwarding**. Leave other settings as default.

![Port-virtualbox](https://dev-to-uploads.s3.amazonaws.com/i/mwaxtb2cb6ow2dsfc65t.png)

### Add a new entry

Click on the **+** icon on the top-right corner to add a new rule.

![add-virtualbox](https://dev-to-uploads.s3.amazonaws.com/i/4uszmmam1c0v3id8k8me.png)

### The rule

**Name:** ssh
**Protocol:** TCP
**Host Port:** 3022
**Guest Port:** 22
Leave others empty

> What we're telling here is, basically forward all connections to the port 3022 on host machine to the port 22 on the guest machine. If you didn't know, SSH uses port 2

![entry-virtualbox](https://dev-to-uploads.s3.amazonaws.com/i/nbqn8pkzpoxxjs682n6n.png)

### Done! Now let's connect

Open your terminal and type

```bash
~$ ssh -p 3022 <username>@127.0.0.1
```

Here,
```bash
~$ ssh -p 3022 ubuntu-1@127.0.0.1
```

![command-virtualbox](https://dev-to-uploads.s3.amazonaws.com/i/3efnuf9yndx2yp0nosbn.png)

**Enter the Password of your <username> that you are logging into and we're done**

![Done-virtualbox](https://dev-to-uploads.s3.amazonaws.com/i/mculee1fj712ix40qd4o.png)

Hope this article helped. Give this article a like, unicorn, and save it for later. Share it with your friends and let them know this useful trick. 

Next article on how you can run a VirtualBox without running it's GUI. So combining SSH access and no-GUI, VirtualBox made convenient. 

My Blog: https://www.tharunshiv.com

Written by,
{% user developertharun %}

# Thank you for reading, This is Tharun Shiv a.k.a Developer Tharun

![Tharun Shiv](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xtxq6bdms36fmn62450h.png)