VirtualBox: Connect to Guest from Host by SSH (E.g. Putty)

VirtualBox is a general-purpose full virtualizer for x86 hardware, targeted at server, desktop and embedded use. You can install and run quite a few different OS by VirtualBox. For example, you can install Fedora with VirtualBox, then install SSHD service within Fedora OS. By some simple Network configuration, you can connect to Fedora OS from your Host Machine OS such as Windows 10. This article is to tell how to do this step by step.

Photo by Goran Ivos on Unsplash

Assuming you already installed VirtualBox and have one Virtual Image with Fedora OS installed.

Install OpenSSH Server on Fedora

Depends on how you installed Fedora, you can open one terminal and search openssh package by yum command. For example,

> sudo yum search openssh | grep server
Last metadata expiration check: 0:06:59 ago on Wed Aug 18 06:58:02 2021.
openssh-ldap.x86_64 : A LDAP support for open source SSH server daemon
openssh-server.x86_64 : An open source SSH server daemon
gsi-openssh-server.x86_64 : SSH server daemon with GSI authentication

In the result list, we got what we want to install: openssh-server.x86_64 then we run install command to install it:

> sudo yum install openssh-server.x86_64
Last metadata expiration check: 0:09:42 ago on Wed Aug 18 06:58:02 2021.
Package openssh-server-8.2p1-2.fc32.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!

If you already installed it, you will get the completely same output as above. Otherwise, it will show how much size of file to download and ask you if go forward to install it. Click Y to install.

Start OpenSSH Server on Fedora

After installation, you can start the openssh server and also make it start automatically at the boot time. See more details on Fedora document Starting an OpenSSH Server.

When OpenSSH Daemon started, you can see its status by below command:

> sudo systemctl status sshd
● sshd.service - OpenSSH server daemon
Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: disabled)
Active: active (running) since Tue 2021-08-17 07:52:40 CEST; 24h ago
Docs: man:sshd(8)
man:sshd_config(5)

Configure VirtualBox Network for Fedora VM

Open VirtualBox Manager and go to the tab of Fedora VM. Click Settings -> Network -> Adapter 1, then click “Port Forwarding” to open “Port Forwarding Ruels”

You can click the green icon with + sign to add one new rule for port forwarding. Then, fill in Host IP, Host Port, Guest IP, and Guest Port.

In Windows, you can get Host IPaddress by ipconfig command and in Fedora you can use ifconfig or ip address. It’s enough to use local IP address, no need to use global IP address.

For Guest IP of Fedora VM, you can use value of inet of interface enp0s8 which is also assgined one local IP address. (Note: you can check all interfaces and their IP addresses by ip address , in case it’s not enp0s8 in your VM)

> ip address show enp0s8 | grep inet | head -1 | grep -m 1 -Eo '([0-9]+.){3}[0-9]+' | head -1
192.168.1.4

When you finish, Click OK to save and close the dialog.

Note: from Host, you cannot ping or connect to the Guest IP address directly. That’s why Port Forwarding is required.

> ping 192.168.1.4Pinging 192.168.1.4 with 32 bytes of data:
Request timed out.
Request timed out.
Request timed out.
Request timed out.
Ping statistics for 192.168.1.4:
Packets: Sent = 4, Received = 0, Lost = 4 (100% loss),

Connect to Guest OS by SSH Client from Host OS

As we forwarded Host port (1022) to Guest port (22), so we can connect to Host port by SSH client: (in fact, it will connect to Guest port 22)

> ssh -p 1022 wenijinew@192.168.0.4
wenijinew@192.168.0.4's password:
Last login: Wed Aug 18 07:59:46 2021 from 10.0.2.2
> cat /etc/system-release
Fedora release 32 (Thirty Two)

If you use Putty, then just fill Host Name (or IP address) and Port accordingly and Open the connection: (See article for more information about PuTTY Configuration)

That’s all! Thanks for reading and happy coding!

--

--

--

A coder, and an artist.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

File or Image Upload Using Livewire Laravel 8 Tutorial

The Wondeful World of OAuth: Bug Bounty Edition

What is the ELK Stack and how to apply it to information security

Welcome to the AWS Community Builders

Defining Infrastructure Declaratively with Crossplane

The Great Resignation and technical debt: finding a way forward

Adding two new powerups: Ammo and Health

Why Every Software Developer Needs ITIL V4 Foundation Certification

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Bruce Wen

Bruce Wen

A coder, and an artist.

More from Medium

Demystifying Docker (But For Real This Time)

Variables in LaTeX documents exported from Emacs Org Mode

libgpiod API usage (Linux shared libraries) On Eclipse- Solving Problem with libgpiod — undefined…

Exporting Solar Panel System Data from Ginlong (Solis) for Data Analysis