I just installed VirtualBox on my mac, created a new Ubuntu Virtual Machine with "Use an existing virtual hard disk file" of the Cloudera Hadoop disk image. I'm able to start and run the virtual machine, however, I'd prefer to ssh into from my terminal. The following produces the message "connect to host port 2222: Connection refused":

ssh root@ -p 2222

I've also tried -p 22

I've also tried using "cloudera" as the user. Is there a VirtualBox setting I need to change to allow SSH?

I've also just tried to create a new linux virtual machine without using Cloudera disk image, and I can SSH into that either.

  • In virtualbox, if you go into Settings and then Network, what does the Attached To field say? – Mark Plotnick Sep 21 '15 at 19:07
  • @MarkPlotnick Attached to: NAT – jKraut Sep 21 '15 at 19:19
  • The answers to this question may help: how to connect to a virtualbox guest – Mark Plotnick Sep 21 '15 at 19:30
  • You might want to look into using vagrant, it makes creating a vm and ssh'ing very easy – gary69 Feb 13 '20 at 17:31

I have a Mac on which I had installed VirtualBox.

So this is what worked for me ...

Click on the cloudera image and click settings Click on Network -> Adapter 1(by default have attached to as NAT) -> Advanced -> Port Forwarding Add a new entry (click on + to add) with the following settings:

Host Port: 1111, Guest Port: 22, leave the host IP and guest IP blank

Connect from your Mac cmd shell using the following

ssh -p 1111 cloudera@localhost

At Ubuntu 18.04 additionally install ssh and reboot

sudo apt-get install openssh-server
  • Thank yo so much – McLan May 30 '19 at 22:41
  • I set the IP addresses as per @Pujochr below, but more importantly, it was ensuring that I had ssh installed on the VirtualBox machine (sudo apt-get install ssh), and then the reboot of the Ubuntu VirtualBox machine that enabled me to log in from the host Mac. – Phil Ryan Aug 22 '19 at 1:45
  • Thanks! it worked once the ssh was installed as the Ubuntu image did not come pre-installed with it. – Andreas Sep 6 '20 at 12:18

Wikipedia say

On most computer systems, localhost resolves to the IP address

your command

ssh root@ -p 2222

Try to connect from mac to your mac and not to your VM.

Try to find the address of your VM and change your command acordingly.

NB: if you just want to ssh from your mac to your VM you can add a "host-only" network adapter to your VM.

`ifconfig -a`

in your ubuntu VM should then show you the ip-address associated with vboxnet0 that you can use for connexting from your mac.


First, make sure that your VM is power-off. Then right-click on VM. Then go to Settings --> Network In the Attached to section, choose Bridged Adapter from the dropdown list. click ok

Now power on the VM Open terminal and type sudo apt-get install openssh-server

Now type ifconfig (if not installed then you have to install it using sudo apt install net-tools) After this command, you will get the ip address like

enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.54.375.20  netmask  broadcast
        inet6 fe80::c5cc:cb0d:b02f:f7f6  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:29:7c:4d  txqueuelen 1000  (Ethernet)
        RX packets 6560  bytes 7484338 (7.4 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2063  bytes 210479 (210.4 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

Take the ip address from (inet 10.54.375.20) take your address which got displayed.

Now in your host pc (your pc) type ssh username@yourip (eg nitin@10.54.375.20) and you will be asked for your VM password. Once you in you can access your VM command line.


If you worked only with a provided harddisk-file, this implies for me that you created the VM yourself. The default network-setting for new VMs is "NAT" so you have to create a NAT-Rule, routing the host's port 22 to the VM's port 22.

I don't know about MacOS, but under Linux, you'd have to use a port > 1024. I usually use ports starting with 10000 and the respective service-port. In your case, I'd make a port-mapping of 10022 -> 22. For the entry in the "host"-column I use and for the guest-side as addresses.

You get to the menu via "Right-click on VM" in VirtualBox Manager -> "Change" -> "Network"-tab -> "Port-Forwarding"

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.