Trying to SSH to local VM Ubuntu with Putty

VirtualBox will create a private network (10.0.2.x) which will be connected to your host network using NAT. (Unless configured otherwise.)

This means that you cannot directly access any host of the private network from the host network. To do so, you need some port forwarding. In the network preferences of your VM you can, for example, configure VirtualBox to open port 22 on 127.0.1.1 (a loopback address of your host) and forward any traffic to port 22 of 10.0.2.1 (the internal address of your VM)

This way, you can point putty to Port 22 of 127.0.1.1 and VirtualBox will redirect this connection to your VM where its ssh daemon will answer it, allowing you to log in.


I wanted to use putty to connect to my ubuntu on virtual box (comfort reasons, the VB is just weird. I can't work unless it is on a proper terminal). Anyway,

  1. Make sure ssh client is installed on your Linux. If not, install it sudo apt install ssh.
  2. Power off the OS.
  3. Now on your VB go to Settings -> Network -> on Adapter 1 choose Host-only adapter->click OK.
  4. Now start your OS. Run ifconfig; now the inet address is your IP.
  5. Use this and run it on your putty. Login with your credentials.

The only disadvantage of using host-only adapter is that your guest OS won't have access to the wider network (eg the Internet).

If you also need your VM to have internet access, leave Adapter 1 as NAT and enable Adapter 2, configured as a Host-Only adapter. This will allow your VM to connect to the internet using NAT as well as make a local connection to your Host using Host-Only.


First you need to decide if your VM connected to your host machine via a bridge connection or via a NAT, but ether way you'll need to put the VM IP address in putty to be able to connect to ip, in the VM terminal run this command to show you the machine IP address (and no 127.0.0.1 is not the machine IP address)

VM # ip addr show

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 52:54:00:d9:16:b3 brd ff:ff:ff:ff:ff:ff
    inet 10.0.2.15/24 brd 10.0.2.1 scope global eth0
       valid_lft forever preferred_lft forever

in this case my IP address will by 10.0.2.15,

First try to make sure you can communicate on a basic level with VM, open a terminal window on your host, and try to ping the VM

HOST # ping 10.0.2.15

PING 10.0.2.15 (10.0.2.15) 56(84) bytes of data.
64 bytes from 10.0.2.15: icmp_seq=1 ttl=64 time=0.045 ms
64 bytes from 10.0.2.15: icmp_seq=2 ttl=64 time=0.110 ms
64 bytes from 10.0.2.15: icmp_seq=3 ttl=64 time=0.099 ms

If you get ant result, then make sure you have a ssh service running on the VM, in the terminal on your VM type as root,

VM # netstat -lnpt | grep 22
tcp   0  0  0.0.0.0:22  0.0.0.0:*  LISTEN  2361/sshd

This tell as we have a service/process with PID(2361) called sshd (OpenSSH daemon) listening to port 22.

You can test if the service work correctly by trying to ssh to it from the VM it self,

VM # ssh 127.0.0.1

Next you neet to make sure that you are not blocking port 22 in your firewall/iptables, I can not believe so, but check it out anyway. In the VM type this command to show you the iptables,

VM # iptables -nvL INPUT

in the output you should have line like this one:

0  0  ACCEPT  tcp  --  *  *  0.0.0.0/0  0.0.0.0/0  tcp  dpt:22  ctstate  NEW