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 -vOpenSSH_7.2p2, LibreSSL 2.4.1debug1: Reading configuration data /etc/ssh/ssh_configdebug1: /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 outssh: connect to host x.x.x.x port 22: Operation timed outOn the VM terminal, the following is displayed:connection from ubuntu server to the same ubuntu serverWhen I do the same, from ubuntu server (VM)to ubuntu server (vm) - locally and use:ssh user@0.0.0.0everything works fine. I can connectThe same thing doesn't work from outside the VM environment.
Unable to connect to SSH server from MacOS
ubuntu;ssh;virtualbox;virtual machine;macintosh
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