Despite the tremendous amount of work that VirtualBox has put in to make this process easier, I really just cannot get it working properly.

The goal: To be able to run a headless VirtualBox VM, which I can SSH into from the host computer.

The current error message when I attempt to SSH from the host to the guest:

$ ssh -p 2222 user@localhost
ssh_exchange_identification: Connection closed by remote host

SSH is working on the guest VM just fine, and I the guest can SSH to itself without a problem. I am pretty sure that the problem is the forwarding of the connection from the host to the guest, because my attempts to SSH to the guest don't even appear in the guest's SSH logfiles. Thus, the connections must never be reaching the machine.

Current configuration of VirtualBox:

I have followed the two primary methods of port forwarding through the VB NAT, as described in both the VBox manual, and in various forums. I have used the 'old' way:

$ VBoxManage setextradata "VM Name Here" \
      "VBoxInternal/Devices/e1000/0/LUN#0/Config/guestssh/Protocol" TCP

$ VBoxManage setextradata "VM Name Here" \
      "VBoxInternal/Devices/e1000/0/LUN#0/Config/guestssh/GuestPort" 22

$ VBoxManage setextradata "VM Name Here” \
      "VBoxInternal/Devices/e1000/0/LUN#0/Config/guestssh/HostPort" 2222

As well as the 'new' way, from the VBox manual:

VBoxManage modifyvm "VM name" --natpf1 "guestssh,tcp,,2222,,22"

I know that the first set of commands took effect because I can see them in the *.vbox XML configuration file for the VM, and I know the second command worked because when I look at:

VBox --> (Select VM) --> Settings --> Networking --> Advanced --> Port Forwarding

I see my created 'guestssh' port forward definition in the dialog.

In addition, I have added the line:


to the guest's /etc/hosts.allow, and no firewalls are running on either the host or guest.

The host is Ubuntu 11.04. The guest is Fedora 16. VirtualBox is version 4.1.0 r73009.

Does anyone have any ideas?


Okay, well, apparently the issue was in the guest VM, with regard to the firewall:

1) iptables -L showed that everything was set to 'ALLOW'
2) Looking at the Firewall GUI, SSH was allowed through
3) I had disabled the Firewall from the GUI

None of these solved the problem.

$ sudo systemctl stop iptables.service

Didn't solve it, either. BUT:

$ sudo systemctl disable iptables.service

Did, finally, fix it. This seems incredibly heavy-handed, but nothing else was working. I'm not sure if this was a bug, or what, but it works now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.