Step-by-Step Guide: SSH Into Your VirtualBox Ubuntu VM from Windows 11
If you're running an Ubuntu virtual machine in VirtualBox on a Windows 11 host, you might want to connect to it remotely via SSH. This guide walks you through the entire process, from enabling SSH on the VM to connecting from your Windows machine.
1. Install OpenSSH Server on the Ubuntu VM
First, update the package list and install the OpenSSH server:
sudo apt update
sudo apt install openssh-server -y
2. Check SSH Status
Ensure the SSH service is running:
sudo systemctl status ssh
If it's not active, start and enable it:
sudo systemctl start ssh
sudo systemctl enable ssh
3. Find the VM's IP Address
Run the following command in the VM to get its IP address:
ip a
Look for an IP like 192.168.x.x on the interface that corresponds to your network (usually enp0s3 or similar).
4. Configure VirtualBox Network Settings
By default, VirtualBox uses NAT networking, which prevents direct SSH access. You need to set up port forwarding or switch to bridged networking.
Option A: Port Forwarding (NAT)
- In VirtualBox, select the VM and go to Settings > Network > Adapter 1.
- Click Advanced > Port Forwarding.
- Add a new rule:
- Name: SSH
- Protocol: TCP
- Host IP: 127.0.0.1
- Host Port: 2222 (or any unused port)
- Guest IP: (leave blank or enter VM's IP)
- Guest Port: 22
Now you can SSH from Windows using:
ssh username@127.0.0.1 -p 2222
Option B: Bridged Networking
- In VirtualBox, go to Settings > Network > Adapter 1.
- Change Attached to to Bridged Adapter.
- Choose your physical network adapter.
- Restart the VM and check its IP again; it should now be on the same subnet as your host.
Then SSH directly:
ssh username@192.168.x.x
5. Connect from Windows 11
Open Command Prompt or PowerShell and use the appropriate SSH command from the option you chose. You'll be prompted for the Ubuntu user's password.
Tip: If you get a "Permission denied" error, verify the username and password, and ensure SSH is allowed through the VM's firewall.
6. Optional: Use Key-Based Authentication
For a passwordless login, generate an SSH key pair on your Windows machine:
ssh-keygen -t rsa -b 4096
Then copy the public key to the VM:
ssh-copy-id username@vm-ip
Now you can SSH without a password.
Wrapping Up
With these steps, you can seamlessly SSH into your VirtualBox Ubuntu VM from Windows 11. Whether you prefer port forwarding or bridged networking, remote access is just a few commands away.