DEV Community

Cover image for How to SSH Into a VirtualBox Ubuntu VM From Windows - Password Authentication (Step-By-Step Guide)
Kevin Suchetan
Kevin Suchetan

Posted on

How to SSH Into a VirtualBox Ubuntu VM From Windows - Password Authentication (Step-By-Step Guide)

If you're running Ubuntu in VirtualBox on Windows and want to SSH into it from your Windows terminal - this guide walks you through everything clearly.

This is perfect if you want to:

  • Practice Linux server administration

  • Access your VM like a remote machine

  • Simulate multiple user sessions

  • Run commands from Windows without using the VM window

Let’s get started.


Step-1. Install OpenSSH Server Inside the Ubuntu VM

  • Open your Ubuntu terminal and switch to root (optional but convenient):
sudo -i
Enter fullscreen mode Exit fullscreen mode
  • Install the SSH server:
apt install openssh-server
Enter fullscreen mode Exit fullscreen mode

Image showing

  • Check whether SSH server is running:
systemctl status ssh
Enter fullscreen mode Exit fullscreen mode

Image showing

If you see "active (running)", you're good.


Step-2. Enable Password Authentication (Optional but Needed Here)

SSH sometimes disables password login by default.

  • Open the SSH server config:
nano /etc/ssh/sshd_config
Enter fullscreen mode Exit fullscreen mode
  • Find this line:
#PasswordAuthentication no
Enter fullscreen mode Exit fullscreen mode
  • Change it to:
PasswordAuthentication yes
Enter fullscreen mode Exit fullscreen mode

Image showing the

  • Save and exit(Ctrl X and then 'y'), then restart SSH:
systemctl restart ssh
Enter fullscreen mode Exit fullscreen mode

Step-3. Set Up VirtualBox Port Forwarding (The Key Step)

  • Your VM is behind VirtualBox's NAT network, which means:
    • It can access the internet
    • But outside machines (like Windows) cannot access the VM directly
  • To allow SSH traffic from Windows to Ubuntu VM, we create a forwarding rule.

In VirtualBox:

i. Select your Ubuntu VM

ii. Settings > Network > Adapter 1

iii. Attached to: NAT

iv. Click Advanced > Port Forwarding

Image showing Port Forwarding Option

  • Add rule:
Name Protocol Host IP Host Port Guest IP Guest Port
SSH TCP 127.0.0.1 2222 22

Image showing port forwarding rule

(Guest IP can be left blank - VirtualBox fills it automatically)

  • This tells VirtualBox: "When Windows sends traffic to 127.0.0.1:2222, forward it to the VM's port 22."

Step-4. Check if Windows Has the SSH Client

  • Windows 10 and 11 already ship with OpenSSH client.

Use Windows terminal to Verify:

ssh -V
Enter fullscreen mode Exit fullscreen mode

If you get a version number, it's installed.

  • If not, enable it:
    Settings > System > Optional features > Add a feature > "OpenSSH Client"

  • No firewall changes are usually needed since outbound connections are allowed.

Step-5. SSH From Windows Into the Ubuntu VM

  • Open Windows Terminal or CMD and run:
ssh -p 2222 <your-ubuntu-username>@127.0.0.1
Enter fullscreen mode Exit fullscreen mode
  • Enter your Ubuntu user password - and you're inside the VM from Windows!

Image showing ubuntu user login inside windows


Wrap-Up

With just NAT port forwarding and a few configuration tweaks, your Windows machine can SSH into your Ubuntu VM exactly like a real remote server. Perfect for learning Linux, DevOps, or cloud workflows.

If you found this helpful, drop a comment - happy hacking!

Top comments (0)