• Windows 7 64-bit host OS running VirtualBox 4.2, with Ubuntu 12.04 guest OS.
  • OpenSSH server is installed and running (ssh -v localhost connects locally in the guest machine).
  • Can SSH to external servers (no outbound Windows firewall rule blocking port 22)
  • Can ping the IP of the guest (


Using PuTTY to SSH to the IP of the guest OS (, PuTTY returns almost immediately with

Network error: connection refused

How can I diagnose & resolve this issue?

11 Answers 11


Are you sure the IP is for the guest OS. I had the same problem and it turned out that the IP I had been using all along, the was actually the Windows interface IP and the host OS IP was

You can verify by doing ipconfig / ifconfig on both.

NOTE: I had also setup a static IP which it turns out I didn't need at all. In case you try from the start I found this tutorial to be better.

  • 6
    +1, The VirtualBox default is to create a guest whose virtual network adapter is NAT'ed through VirtualBox itself. Therefore such a guest would be able to SSH out, and would be able to SSH itself, but it would not be able to receive SSH connections until Port Forwarding rules were created in VirtualBox. Mar 17, 2013 at 12:30
  • +1 After 1h of Google-mess, finally! I thought the .101 was the guest not the host!
    – q9f
    Jul 8, 2014 at 17:33

None of the other solutions are good because:

  1. There is no point to ssh to your guest via bridge if the guest will loose access to internet
  2. All the other solutions above tell you to build a rocket to cross the road.


  • Host Ubuntu Desktop 16.04
  • Guest Ubuntu Server 16.04 (Running on Virtual box 5)


SSH connection refused


  1. Shut your guest Ubuntu down
  2. On Virtualbox go to Setting>network>Adapter1>Advanced>Portforwarding
  3. Name=SSH Hostport=2022 (or any port but 22) Guestport(22)
  4. Reboot your guest
  5. On you host open a Putty or whatever you use for SSH
  6. ssh [email protected] -p2022 (or any port you mentioned as hostport)
  7. Have fun you are in
  • i have problem with this: On Virtualbox Setting>network>Adapter1>Advanced>Portforwarding is gray not clickable. imgur.com/seT3p02
    – SL5net
    Apr 2, 2019 at 11:30
  • @SL5net turn off the VM Nov 8, 2019 at 5:31
  • hey @SL5net make sure NAT is selected in "Attached to" Jun 17, 2020 at 11:02

The following works for me:





So, basically I changed part of the file { /etc/network/interfaces } as follows:


auto eth1
iface eth1 inet static


auto eth1
iface eth1 inet static

Works: ssh [email protected]

  • Don't know why, this worked for me. Thanks @Mause Oct 4, 2017 at 11:44

You should check that your guest OS firewall is not blocking incoming connections on port 22.

  • 1
    The guest OS firewall is disabled. That is the default, and I verified it is disabled with sudo ufw status.
    – Eric J.
    Sep 25, 2012 at 3:22

Hey I'm just returning to the first page I found on my mini-saga of troubleshooting and research, hoping this tutorial I made can save someone else all the hassle.

Start-to-end guide on setting up a CentOS server with Oracle VM:

Part I – Virtual Machine Setup

  1. Install Oracle VM VirtualBox and the expansion pack here.
  2. Download the CentOS minimal installation here.
  3. For this tutorial, I’m using an Ubuntu client. The ISO for that can be found here.
  4. Create the CentOS server and your client virtual machines.
  5. Setup the CentOS VM. a. Open Installation Destination and press Back. b. Go to Network & Hostname if you want to change your hostname, which I recommend. c. Feel free to configure items under Localization. Everything else is handled automatically by VirtualBox. d. Press begin installation. e. Create both a root account and a normal account. Make sure the latter has administrator rights. f. Once the loading bar is full, press Reboot.
  6. Setup your client VM. a. Install VirtualBox guest additions.

Part II – Virtual Network Configuration

  1. In VirtualBox, press CTRL+W.
  2. Create a new host network. a. If you receive an error, this is likely due to your host OS causing VirtualBox problems installing its drivers. You will need to fully uninstall VirtualBox and reinstall the latest version. Make sure to run the installation as admin.
  3. Under the Adaptor tab, select “Configure Adapter Manually”
  4. For Windows, open the Command Prompt and type ipconfig.
  5. Scroll through the output until you find the name of the host-only network you just created. Use this IPv4 Address and Mask for the VirtualBox network configuration.
  6. Close the Host Network Manager.
  7. Open the settings of your client VM. Under Network, Enable Adapter 2, select Host-only Adapter and then the name is the name of your newly-created host-only network.
  8. Repeat the last step for your CentOS server VM. Additionally, go to Adapter 1’s Port Forwarding under the Advanced tab and create a new rule. Set both the host and guest ports to 22.
  9. Before closing the advanced settings, note the MAC address.

Part III – Server Configuration

  1. Launch your CentOS VM.
  2. Run yum check-update, yum upgrade, and yum clean all.
  3. Run nmtui.
  4. Hit enter over “Edit a connection.”
  5. You should see “enp03s” and a “Wired Connection 1”. a. If you have two connection options but are unsure of which is which, go to edit one. If the device value matches the MAC address seen under Adapter 1 from Part II, then it’s your NAT connection, otherwise its your host-only connection.
  6. Edit your Host-only connection: a. Set IPv4 configuration to “manual.” b. Show IPv4 configuration c. In VirtualBox, press CTRL+W. Next to your Host-only network name, you should see and IP Address/Mask combination of the form “[ip]/[mask].” On your server under IPv4 configuration, this is what you will type after pressing <Add…>. d. Go down and press OK.
  7. Make sure “Automatically connect” is checked for both your Host-only and NAT connections.
  8. Navigate out of nmtui and reboot.

Part IV – Client Configuration & Usage

  1. Boot your Client VM.
  2. (optional) Edit /etc/hosts to include the a line of the form: [serv_ip_addr] [hostname] Where serv_ip_addr is the ip address of your CentOS server (second output of hostname -I in your CentOS terminal). This will allow you to use whatever you chose for [hostname] interchangeably with the ip address of your server. I typically just set this to the hostname chosen in part II.
  3. If everything worked up to this point, you should be able to ssh [user]@[hostname] into your CentOS server. If this is not the case, you may need to install openssh-client and openssh-server on your machines.

Part V – Serving Up Websites

  1. This is an excellent guide on hosting your own websites from a setup as described above.

Maybe it's an issue with access control. To disable it and allow full access, as root:

xhosts +

I had a similar issue with VNC viewer

  • 1
    I really doubt that, IMHO sshd has nothing to do with X -- in contrast to vnc.
    – mpy
    Mar 16, 2013 at 20:44

Problem was solved by enabling the DHCP server on the VirtualBox network adapter.

VirtualBox (latest version, version 5) -> File -> Preferences -> Network -> Host-only networks (tab) -> Host-only networks details (Icon tool) -> DHCP Server

  1. Tick Enable Server
  2. Fill in the IP address
  3. OK, OK
  4. Restart the virtual machine

My settings for step 2

  1. Server Address:
  2. Server Mask:
  3. Lower Address Bound:
  4. Upper Address Bound:

Secure Shell (SSH) is a protocol for logging into and executing commands on remote machines. It provides secure encrypted communications. If you plan on accessing your machine remotely via SSH over a firewalled interface, enable this option. You need the openssh-server package installed for this option to be useful.

Here comes the information that the package openssh-server has to be installed. After doing that on the guest and a restart of the vm you can use ssh.

  • I didn't restart my Ubuntu 16.04 and it still worked. Thanks :) Oct 12, 2018 at 21:51

I had to solve this problem by adding an ufw rule for the 2nd adapter:

ufw allow in on enp0s8 to port 22 proto tcp

where enp0s8 is the name of my 2nd adapter (on old Ubuntu distros this was eth1).


In your Linux box (VirtualBox Ubuntu), open the Terminal and enter the following command: sudo service ssh start

Try connecting to it again after this

Oh my bad I missed what gronostaj pointed out

OK sometimes the solutions are really simple. recently I faced the same issue with Slackware guest on windows 7 host. All i had to do was ifconfig up eth'X' and assign IP 192.168.56.xxx sub net (if host only adapter) This question is almost one year old, so I'm mentioning this for someone like me stumbles on this page searching for "ssh connection refused" ;-)

  • OP had stated that local SSH connections work, so the server is running.
    – gronostaj
    Mar 16, 2013 at 22:02

Had the same problem, solved it by adding a virtual hard drive to the VM, which had none.

  • That means your problem was different. If your VM didn't have a hard drive it wasn't booted to an OS, which OPs VM was. Please read questions carefully to make sure you understand them before answering. May 13, 2019 at 20:49
  • This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review May 13, 2019 at 20:49
  • My VM was booted on a Linux 32-bit ISO file, with no additional virtual hard drive May 15, 2019 at 6:15
  • Which means you were running a "Live" Linux session, which is definitely not what OP was dealing with. We're glad you solved your problem, but your solution is not the solution, or particularly even close, to what OP was experiencing. May 15, 2019 at 15:20
  • 1
    You are absolutely correct, I did not realize OP's problem was so specific. That said, considering I got the same error message, I will keep the answer here, just in case someone with my problem ends up here too. May 22, 2019 at 20:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .