18

Setup

  • 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 (192.168.56.101)

Problem

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

Network error: connection refused

How can I diagnose & resolve this issue?

10 Answers 10

9

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 192.168.56.101 was actually the Windows interface IP and the host OS IP was 192.168.56.103.

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.

  • 5
    +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. – Gord Thompson Mar 17 '13 at 12:30
  • +1 After 1h of Google-mess, finally! I thought the .101 was the guest not the host! – Afri Jul 8 '14 at 17:33
5

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.

Scenario

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

Problem

SSH connection refused

Solution

  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 user@127.0.0.1 -p2022 (or any port you mentioned as hostport)
  7. Have fun you are in
2

The following works for me:

Before:

vboxnet0: 192.168.56.1
eth1:     192.168.56.1

After:

vboxnet0: 192.168.56.1
eth1:     192.168.56.101

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

Before:

auto eth1
iface eth1 inet static
address 192.168.56.1
netmask 255.255.255.0 

After:

auto eth1
iface eth1 inet static
address 192.168.56.101
netmask 255.255.255.0 

Works: ssh username@192.168.56.101

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

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 :) – Oren Milman Oct 12 '18 at 21:51
1

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 '12 at 3:22
1

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 '13 at 20:44
1

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: 192.168.56.100
  2. Server Mask: 255.255.255.0
  3. Lower Address Bound: 192.168.56.101
  4. Upper Address Bound: 192.168.56.200
1

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.
0

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

ufw allow in on enp0s8 to 192.168.56.101 port 22 proto tcp

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

-1

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 255.255.255.0 (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 '13 at 22:02

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.