1

On a MacOSSierra I'm running VirtulBox with Ubuntu 16.4 Server (CLI) I'm trying to establish a SSH connection from Mac to the VM (they are both on the same machine)

Mac Terminal:

usermac-MacBook-Pro:~ usermac$ ssh user@x.x.x.x -v
OpenSSH_7.2p2, LibreSSL 2.4.1
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 20: Applying options for *
debug1: Connecting to x.x.x.x [x.x.x.x] port 22.
debug1: connect to address x.x.x.x port 22: Operation timed out
ssh: connect to host x.x.x.x port 22: Operation timed out

On the VM terminal, the following is displayed:

connection from ubuntu server to the same ubuntu server

When I do the same, from ubuntu server (VM)to ubuntu server (vm) - locally and use:

ssh user@0.0.0.0

everything works fine. I can connect

The same thing doesn't work from outside the VM environment.

4
  • Just guessing - Could it be a Virtual Networking problem? Can you ping <vm_ipaddress> from HOST ? – lese Nov 15 '16 at 15:44
  • I have able to ping everything. Tried with: google.com, 8.8.8.8, localhost, x.x.x.x (the ip address displayed after bash command <hostname -I> – Vishera Nov 15 '16 at 15:47
  • anything strange into your HOST /etc/ssh/ssh_config – lese Nov 15 '16 at 15:55
  • In the HOST /etc/ssh/ssh_config there is nothing strange, I suppose. I have configured it and tried different variations. Right now it's all default, nothing modified after a purge and reinstall of the SSH service. I'm sort of new into this, so could you let me know, what I shall modify, if there is anything? – Vishera Nov 16 '16 at 7:51
1

Assuming you are using the default NAT network adapter (which works well for most use cases), in order to connect to your virtual machine from your host machine, you will first need to set up port forwarding. In the VirtualBox GUI, bring up the VM settings, then go to Network > Advanced > Port Forwarding. Choose "22" for the guest port and an arbitrary port number for the host port (I like to use "2222"). Press "OK" to exit out of all of the dialogs and apply the settings.

Now you will be able to connect to your VM at the chosen port on your local system. Make sure to use "localhost" or 127.0.0.1 as the hostname. For instance:

sssh user@localhost -p 2222
5
  • This is exactly what I have tried last night. I came here to update it. This is exactly the way it solves it. For some reason, VirtualBox only works with port forwarding and cannot connect to the IP address of the VM. Thanks a lot for your help. – Vishera Nov 17 '16 at 8:52
  • @Vishera that's because VirtualBox creates a virtual private network for the VMs. The IP that gets assigned to the VM only is routable from within that network, which is why you can't use that IP to ssh to your VM - your host OS isn't on that virtual network. – jayhendren Nov 17 '16 at 17:37
  • And that means, that if I want to host a service or website or anything on a VM Virtual machine and access it from outside the private network, I won't be able to do that with VM? Or even if I want to access this very VM machine from another computer? – Vishera Nov 17 '16 at 20:21
  • You can do that with port forwarding or with bridged networking (there are other solutions as well). For instance, if you have a vm "X" running a website, and X is hosted on host "A", and you forward port 80 on X to 8080 on A, you can browse the website from a different host "B" by going to http://A:8080 in your web browser on B. – jayhendren Nov 17 '16 at 20:47
  • that sounds highly plausible. I'm new to Virtualization and I appreciate your help – Vishera Nov 17 '16 at 21:17
-1

Check IPTables, if SSH is working fine on the VM console that puts it to some external access issue. Try running (as root or sudo) iptables -F or check the connection settings e.g correct IP or NAT settings. Try setting the VM to bridged adapter and give it a static address if possible

1
  • I have tried that as well, i have also tried with 2 NAT's tried to configure it in any means possible. The only solution which worked, was the one with port forwarding and connecting with localhost. to the port of the VM. – Vishera Nov 17 '16 at 8:55

Your Answer

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

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