DEV Community

Cover image for Part 5: Switching on SSH on Ubuntu in VirtualBox: When Clipboard Fails and Firewall Blocks
Melissa
Melissa

Posted on Edited on

Part 5: Switching on SSH on Ubuntu in VirtualBox: When Clipboard Fails and Firewall Blocks

Why I needed SSH in the first place

Bidirectional clipboard in Oracle VirtualBox is unreliable and often just doesn't work. I have long VyOS and Linux commands to type and I wanted to avoid typos, so I decided to SSH from Windows into my Ubuntu VM and copy-paste that way.

My setup

  • VirtualBox Ubuntu VM
  • Adapter 1: NAT (for internet)
  • Adapter 2: Host-Only Adapter (for SSH from Windows)
  • VirtualBox Host-Only Network: 192.168.56.1/24
  • Ubuntu interface for it: enp0s8 - 192.168.56.104/24

Step 1: Enable Host-Only Adapter and give it a static IP

In VirtualBox > VM Settings > Network > Adapter 2 > Enable, Attached to: Host-Only Adapter, Name: VirtualBox Host-Only Ethernet Adapter.

Inside Ubuntu:
ip addr add 192.168.56.104/24 dev enp0s8
make permanent in /etc/netplan/01-netcfg.yaml then:
sudo netplan apply

Check:
ip a show enp0s8
ss -tlnp | grep 22

Step 2: The strange ping problem

From both Ubuntu and Windows PowerShell:
ping 192.168.56.1 -> WORKS both ways
ping 192.168.56.104 -> TIMED OUT from Windows to Ubuntu
ssh user@192.168.56.104 -> TIMED OUT / No route

Checked on Ubuntu:
sudo ufw status
inactive - so Ubuntu is not blocking

Step 3: Isolating it to Windows Firewall

In Windows PowerShell as Admin:
Set-NetFirewallProfile -Profile Private -Enabled False
ping 192.168.56.104 -> WORKS!
Set-NetFirewallProfile -Profile Private -Enabled True
back to TIMED OUT
Conclusion: Windows Defender Firewall Private profile was blocking the reply.

PROBLEM 1: Wrong adapter name

Get-NetAdapter -Name "VirtualBox"
=> No MSFT_NetAdapter objects found

The fix - list ALL adapters:
Get-NetAdapter | Format-Table Name, InterfaceDescription, Status -AutoSize
Result: Ethernet 3 Up VirtualBox Host-Only Ethernet Adapter

PROBLEM 2: The WhatsApp asterisk trap

Get-NetAdapter | Where-Object {$.Name -like "Virtual*"} loses * in WhatsApp.
Use:
Get-NetAdapter | Where-Object {$
.Name -match "Virtual"} | Format-Table Name, Status -AutoSize

PROBLEM 3: No Network Profile (The real bug)

Get-NetIPAddress -InterfaceAlias "Ethernet 3"
shows 192.168.56.1 /24 - Correct

Get-NetConnectionProfile -InterfaceAlias "Ethernet 3"
=> No MSFT_NetConnectionProfile objects found

Meaning Windows saw Ethernet 3 as Unidentified Network with no profile. Any rule for Private never applied.

THE FIX (works even without a profile):

Run PowerShell as Administrator:
New-NetFirewallRule -DisplayName "Allow ICMP Host-Only" -Direction Inbound -Protocol ICMPv4 -RemoteAddress 192.168.56.0/24 -Action Allow -Profile Any
Enable-NetFirewallRule -DisplayName "File and Printer Sharing (Echo Request - ICMPv4-In)"

Then test:
ping 192.168.56.104

SSH - Correct syntax:

On Ubuntu, check user and ssh service:
whoami
sudo systemctl status ssh
sudo systemctl start ssh

On Windows (PowerShell):
ssh ubuntumelissa@192.168.56.104
Format is ssh USER@IP - no space, no extra hostname

QUICK COPY COMMANDS FOR NEXT TIME:
Get-NetAdapter | Format-Table Name, InterfaceDescription, Status -AutoSize
Get-NetIPAddress -InterfaceAlias "Ethernet 3" | Format-Table IPAddress, PrefixLength -AutoSize
ipconfig /all
New-NetFirewallRule -DisplayName "Allow ICMP Host-Only" -Direction Inbound -Protocol ICMPv4 -RemoteAddress 192.168.56.0/24 -Action Allow -Profile Any
ping 192.168.56.104
ssh ububtumelissa@192.168.56.104

Next up: TOR relay VPS maintenance practice on the Ubuntu in Oracle VM before doing it for real on a VPS.

Top comments (0)