VirtualBox Ubuntu Server SSH Setup: Complete Development Guide

Complete Guide to Setting Up an SSH Development Environment with VirtualBox + Ubuntu Server 24.04

As of 2025, using VSCode’s Remote SSH feature has become the best practice when building a development environment with VirtualBox. This article provides detailed instructions so that even beginners can reliably set up their environment.

Understanding VirtualBox SSH Connections – Interactive Diagram

🔍 Understanding VirtualBox SSH Connections

VirtualBox Environment Overview

💻
Your PC
Windows/Mac/Linux
📦
VirtualBox
Virtualization Software
🐧
Ubuntu Server
Virtual Machine
🌍
Internet
External Network

🎯 Key Points to Understand

  • VirtualBox is software that runs another computer virtually on your PC
  • Ubuntu Server is an independent Linux OS running inside VirtualBox
  • Normally, virtual machines exist in their own private network
  • Special configuration is required to access the VM from outside

Connection Flow

1 Launch SSH client on host PC (your PC)
2 Connect to localhost:2222
3 VirtualBox receives request and forwards the port
4 Forwarded to VM’s 10.0.2.15:22
5 Ubuntu Server’s SSH server responds

How NAT Networking Works

🌐 External Network

Host PC’s Network

IP: 192.168.1.100

❌ Direct access not possible

🛡️ NAT (Network Address Translation)

VirtualBox’s Virtual Router

External IP: 192.168.1.100

Internal IP: 10.0.2.1

✅ Translation & forwarding function

🔒 Private Network

Virtual Machine’s Network

IP: 10.0.2.15

✅ Protected environment

💡 Benefits of NAT

  • 🛡️ Security: Safe because external direct access is blocked
  • 🌍 Internet Connectivity: VM can access external networks
  • 🏠 Same as Home Router: Your home WiFi router uses the same NAT technology
  • 📦 IP Address Conservation: Multiple VMs can share the same host IP

🎮 Interactive Demo: Experience NAT in Action

How Port Forwarding Works

🔧 Port Forwarding Configuration

127.0.0.1:2222 ➡️ 10.0.2.15:22

Host port 2222 → Guest port 22

🤔 Why Use Port 2222?

  • Port 22 is the standard SSH port
  • Your host PC might already have an SSH server running
  • Use a different port number (2222) to avoid conflicts
  • Port numbers above 1024 can be freely used
ssh -p 2222 username@127.0.0.1

📊 Port Forwarding Flow

1️⃣ Start SSH Connection

Destination: 127.0.0.1

Port: 2222

ssh -p 2222 user@127.0.0.1
2️⃣ VirtualBox Receives

Check port forwarding rules

Convert 2222 → 22

✅ Rule found! Start forwarding

3️⃣ Arrives at Ubuntu Server

Received IP: 10.0.2.15

Received Port: 22

✅ SSH connection established

🎮 Port Forwarding Simulator

SSH Connection Details

🔐 What is SSH (Secure Shell)?

  • Encrypted secure communication protocol
  • Mechanism for safely operating remote computers
  • Connect using password or key authentication
  • All communication content is encrypted

🔑 Authentication Method Comparison

Password Authentication

✅ Easy to set up

❌ Relatively lower security

❌ Password entry required each time

ssh -p 2222 user@127.0.0.1
# Password prompt appears
🏆 Key Authentication (Recommended)

✅ High security

✅ No password needed

✅ Automatic login possible

ssh-keygen -t ed25519
ssh-copy-id -p 2222 user@127.0.0.1

SSH Connection Steps

1 Client sends connection request
2 Server sends public key (first time confirmation only)
3 Encrypted communication channel established
4 Authentication (password or key)
5 Shell session begins

VSCode Remote SSH Integration

💎 Revolutionary Nature of VSCode Remote SSH

  • Same experience as local development, but remote
  • Files are on the server, processing happens on the server
  • But the operation feels completely local
  • Extensions work remotely too

🔄 How VSCode Remote SSH Works

VSCode (Client)

👁️ UI Display

⌨️ Input Handling

🎨 Syntax Highlighting

SSH Connection

🔐 Encrypted Communication

📡 Bidirectional Data Transfer

⚡ Real-time Sync

VSCode Server

💻 Code Execution

📦 Extension Execution

🔍 File Search

🛠 Debug Processing

~/.ssh/config Configuration Example

Host ubuntu-server
  HostName 127.0.0.1
  Port 2222
  User username
  IdentityFile ~/.ssh/id_ed25519

✨ VSCode Benefits

🔍 Code Editing

IntelliSense

Syntax Highlighting

Auto-completion

🛠 Debugging

Breakpoints

Variable Watch

Step Execution

📦 Extensions

Works Remotely

Language Support

Tool Integration

🔄 Git Integration

Commits

Branch Management

Diff View

table of contents

Introduction: Why SSH Connection is Necessary

When you install Ubuntu Server on VirtualBox, by default you’ll be working with a black console screen. This environment has several limitations:

  • No copy and paste functionality
  • Inconvenient screen scrolling
  • Difficult Japanese input
  • Inefficient file editing

By setting up SSH connection, you can operate comfortably from your familiar terminal or VSCode.

Required Software and Versions

  • VirtualBox: 7.2.2 or later (latest as of January 2025)
  • Ubuntu Server: 24.04 LTS (supported until April 2029)
  • Windows Terminal or Tera Term (Windows)
  • Visual Studio Code + Remote SSH extension (recommended)

Step 1: Download Ubuntu Server 24.04

  1. Visit Ubuntu’s official website
  2. Download Ubuntu Server 24.04 LTS (approximately 3GB)
  3. Remember where you saved the ISO file

Step 2: Create a Virtual Machine in VirtualBox

Creating the Virtual Machine

  1. Launch VirtualBox and click the “New” button
  2. Create a virtual machine with the following settings:
    • Name: Ubuntu Server 24.04 (or any name you prefer)
    • Type: Linux
    • Version: Ubuntu (64-bit)
    • Memory Size: 2048MB or more (4096MB recommended)
    • Hard Disk: Create new (VDI format, dynamically allocated, 20GB or more)

ISO File Configuration

  1. Select the created virtual machine and click “Settings”
  2. Select “Storage”
  3. Click the empty disk icon under “Controller: IDE”
  4. From the disk icon on the right, select “Choose a disk file”
  5. Select the downloaded Ubuntu Server 24.04 ISO file

Step 3: Install Ubuntu Server

Starting the Installation

  1. Start the virtual machine
  2. Select “English” for language (Japanese is not recommended for server version)
  3. Select “Japanese” for keyboard layout
  4. Leave network settings at default and click “Done”
  5. Leave proxy settings blank and click “Done”
  6. Leave mirror server at default and click “Done”

Storage Configuration

  1. Select “Use an entire disk”
  2. Review partition settings and click “Done”
  3. Click “Continue” to confirm

Account Setup (Important)

  1. Enter the following information:
    • Your name: Your name (e.g., John Smith)
    • Your server’s name: Server name (e.g., ubuntu-server)
    • Pick a username: Username (e.g., john) *lowercase only
    • Choose a password: Set a strong password
    • Confirm your password: Re-enter password

SSH Server Installation (Important)

  1. Check “Install OpenSSH server”
  2. Click “Done”
  3. Don’t select anything in Featured Server Snaps and click “Done”

Once installation is complete, select “Reboot Now”.

Step 4: First Boot and IP Address Confirmation

Log into the Virtual Machine

  1. After reboot, log in with your username and password
  2. Check the IP address with the following command:
ip addr show

Or:

hostname -I

Typically, an IP address like 10.0.2.15 will be displayed. This is the address of VirtualBox’s NAT internal network.

Check SSH Server Status

sudo systemctl status ssh

Confirm that it shows “active (running)”. If it’s not running:

sudo systemctl start ssh
sudo systemctl enable ssh

Firewall Configuration

UFW is disabled by default in Ubuntu 24.04, but check just to be sure:

sudo ufw status

If it shows “Status: inactive”, there’s no problem. If it’s enabled:

sudo ufw allow ssh
sudo ufw allow 22/tcp

Step 5: Configure Port Forwarding in VirtualBox

This is the most critical configuration. Let me explain in detail.

What is Port Forwarding?

In VirtualBox’s NAT mode, the virtual machine exists within its own private network (10.0.2.0/24). It cannot be accessed directly from outside (the host machine). By configuring port forwarding, you can redirect access to a specific port on the host machine to the virtual machine.

Configuration Steps

  1. Shut down the virtual machine:
    sudo shutdown -h now
  2. In VirtualBox Manager, select the virtual machine and click “Settings”
  3. Select “Network” → “Adapter 1”
  4. Click “Advanced” to display detailed settings
  5. Click the “Port Forwarding” button
  6. Click the “+” icon to add a new rule
  7. Enter the following settings:
    • Name: SSH (any name you prefer)
    • Protocol: TCP
    • Host IP: 127.0.0.1 (or leave blank)
    • Host Port: 2222 (any number 1024 or above)
    • Guest IP: 10.0.2.15 (virtual machine’s IP)
    • Guest Port: 22
    *Using port 22 for the host port may conflict with the host machine’s SSH service, so 2222 is recommended
  8. Click “OK” to save the settings

Step 6: Test SSH Connection

For Windows

Using Windows Terminal / PowerShell:

ssh -p 2222 username@127.0.0.1

Example:

ssh -p 2222 john@127.0.0.1

Using Tera Term:

  1. Launch Tera Term
  2. Enter the following:
    • Host: 127.0.0.1
    • TCP Port: 2222
  3. Click “OK”
  4. Enter username and password

For macOS / Linux

ssh -p 2222 username@127.0.0.1

Connection Notes

On first connection, you’ll see this message:

The authenticity of host '[127.0.0.1]:2222' can't be established.
ED25519 key fingerprint is SHA256:xxxxxxxxxxxxx
Are you sure you want to continue connecting (yes/no/[fingerprint])?

Type “yes” and press Enter.

Using VSCode’s Remote SSH extension provides a comfortable environment as if you were developing locally.

Install Remote SSH Extension

  1. Launch VSCode
  2. Click the extensions icon on the left (or Ctrl+Shift+X)
  3. Search for “Remote – SSH”
  4. Install “Remote – SSH” provided by Microsoft

Create SSH Configuration File

  1. Open the command palette in VSCode (Ctrl+Shift+P or F1)
  2. Select “Remote-SSH: Open SSH Configuration File”
  3. Select ~/.ssh/config (For Windows: C:\Users\username\.ssh\config)
  4. Add the following configuration:
Host ubuntu-server
    HostName 127.0.0.1
    Port 2222
    User username

Example:

Host ubuntu-server
    HostName 127.0.0.1
    Port 2222
    User john

  1. Save the file

Connect from VSCode

  1. Open the command palette (Ctrl+Shift+P)
  2. Select “Remote-SSH: Connect to Host”
  3. Select “ubuntu-server”
  4. A new window opens, enter your password
  5. When connected successfully, “SSH: ubuntu-server” appears in the lower left

Set Up Development Environment in VSCode

After connecting, the following operations become possible:

  • File editing (with syntax highlighting)
  • Integrated terminal usage
  • Git operations
  • Remote installation of extensions
  • Debug execution

Step 8: Configure SSH Key Authentication (Security Enhancement)

Set up SSH key authentication, which is more secure than password authentication.

Generate Keys on Windows (PowerShell)

ssh-keygen -t ed25519 -C "your-email@example.com"

Copy Public Key to Virtual Machine

Method 1: Manual Copy

Display the public key content:

cat ~/.ssh/id_ed25519.pub

Connect via SSH and execute the following on the virtual machine:

mkdir -p ~/.ssh
chmod 700 ~/.ssh
echo "paste public key content here" >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys

Method 2: Use ssh-copy-id (via WSL)

ssh-copy-id -p 2222 username@127.0.0.1

Update VSCode Configuration

Add the following to ~/.ssh/config:

Host ubuntu-server
    HostName 127.0.0.1
    Port 2222
    User username
    IdentityFile ~/.ssh/id_ed25519

Step 9: Start in Headless Mode (Convenient Usage)

You can start the virtual machine in the background without displaying the GUI window.

Start from Command Line

VBoxManage startvm "Ubuntu Server 24.04" --type headless

Stop

VBoxManage controlvm "Ubuntu Server 24.04" poweroff

Or connect via SSH and run:

sudo shutdown -h now

Troubleshooting

Problem 1: Cannot Connect via SSH

Causes and Solutions:

  1. SSH server is not running
    sudo systemctl start ssh
    sudo systemctl enable ssh
  2. Port forwarding settings are incorrect
    • Verify the guest IP is correct (usually 10.0.2.15)
    • Check if the host port is not already in use
  3. Windows Defender Firewall
    • Allow VirtualBox communication

Problem 2: VSCode Connection Error

Solutions:

  1. Clear the known_hosts file:
    Remove-Item ~/.ssh/known_hosts
  2. Check the syntax of the SSH configuration file

Problem 3: Virtual Machine is Slow

Solutions:

  1. Increase memory (4GB or more recommended)
  2. Increase CPU core count (Settings → System → Processor)
  3. Enable virtualization support (VT-x/AMD-V in BIOS settings)

Network Configuration Options

NAT + Port Forwarding (This Article’s Method)

Advantages:

  • Simple configuration
  • High security
  • Accessible only from host machine

Disadvantages:

  • Cannot be accessed from other PCs on the LAN

Bridged Adapter

Advantages:

  • Accessible from anywhere on the LAN
  • Can be treated like a real machine

Disadvantages:

  • Requires a router
  • Consumes a separate IP address

Host-Only Adapter + NAT (Two Adapters)

Advantages:

  • Combines internet connection and host connection
  • More flexible configuration

Disadvantages:

  • Slightly complex configuration

Summary

The combination of VirtualBox + Ubuntu Server 24.04 + VSCode Remote SSH is one of the most efficient development environments as of 2025. By following the steps in this article, even beginners can reliably set up their environment.

VSCode’s Remote SSH feature is particularly innovative, allowing you to develop within a virtual machine with the same feel as local development. This enables a unified development experience across Windows, macOS, and Linux environments.

Since SSH connection is fundamental in cloud environments (AWS, Azure, GCP) as well, the experience of setting up this environment will be valuable in the future.

The Following Article Was Published in 2021 and Is Preserved Here to Study the Evolution Process

I installed Ubuntu Minimal using VirtualBox, but operating it was difficult because it showed a black console screen instead of a desktop interface. So I decided to connect to this virtual machine using Tera Term. Since this type of environment is overwhelmingly common in the cloud, I recommend that everyone build an environment for learning purposes.

Let’s proceed. I want to make an SSH connection, so I’ll check if the appropriate software is installed.

sudo systemctl status sshd

It’s not installed, so I’ll install it.

sudo apt install ssh

I’ll also check the firewall port opening status. It showed “inactive”, meaning that although it’s installed, it’s not running, so I understand that connections won’t be rejected.

sudo ufw status

Next, I need to configure VirtualBox itself, so I’ll shut down the OS. Before shutting down, I’ll make note of this virtual machine’s IP address.

Click Settings in VirtualBox. Select Network, then click “Advanced” in the Adapter tab to display details.

VirtualBox Network Settings

I’ll use the port forwarding available here. A port configured with port forwarding functions as a gateway for the mapped address port, and all packets sent and received externally are automatically transferred, making SSH connection to the virtual machine possible.

I’ll create a new rule. The name can be arbitrary, and I’ll enter the IP address of the PC I’m operating in Host IP. You can find the IP address by entering the following command in Command Prompt:

ipconfig

I set the Host Port to 5050. Enter the virtual machine’s IP address in Guest IP, and enter 22 in Guest Port.

Port Forwarding Configuration

Now the IP addresses of the operating PC and the VirtualBox virtual machine can send and receive. I’ll start the virtual machine. At this time, if a Windows Defender warning appears, allow access.

Windows Defender Firewall Alert

I’ll verify in Command Prompt whether sending and receiving is actually possible.

telnet 192.168.26.105 5050

The OpenSSH display appeared and connection was confirmed.

Telnet Connection Test

Open Tera Term and enter the Host and TCP Port as follows:

Host: user@192.168.26.105 TCP Port: 5050

Tera Term Connection Dialog

When you press the OK button, an authentication screen appears, so log in by entering the Ubuntu virtual machine’s username and password.

SSH Authentication Screen

Since we’re at it, let’s also try connecting with authentication keys. I’ll create a directory on the virtual machine that will be needed later. I’ll create a directory called .ssh in the home directory and grant appropriate access permissions.

mkdir .ssh

# Change directory permissions to 700 (only owner can read, write, execute)
chmod 700 .ssh

Now, click “SSH Key Generation” in Tera Term’s Settings tab. Press “Generate” to save the public and private keys.

SSH Key Generation in Tera Term

The public key has a .pub extension, and I’ll transfer this to the virtual machine. Transfer is also possible using Tera Term’s functionality. SSH SCP in the File tab does this. In the “From” section at the top, I’ll load the public key with .pub extension that was just generated. I left the “To” section blank. When blank, the file is transferred to the current directory.

SCP File Transfer

I’ll copy the .pub file to the .ssh directory I created earlier with a different filename. I’ll also set appropriate permissions for the created file.

# Copy the public key to the .ssh directory as a file named authorized_keys
cat id_rsa.pub >> .ssh/authorized_keys

# Change permissions of authorized_keys file to 600 (only owner can read and write)
chmod 600 .ssh/authorized_keys

# Delete the transferred public key as it's no longer needed
rm id_rsa.pub

When connecting with Tera Term, I’ll now use key-based connection. I’ll select the private key and connect.

Key-Based Authentication

If you like this article, please
Follow !

Please share if you like it!
table of contents