How to configure ssh OS X host with Linux guest, so I can access my guest OS through SSH. I've tried:

virtualbox guest

But when I tried to ssh from host, it failed:

> ssh localhost
ssh: connect to host localhost port 22: Connection refused

I've tried to set the ip (host, guest on the port forwarding, it gives the same output. I've tried to bind the host to higher address (2222), but got no luck, the host still doesn't listen on port forwarding port. It doesn't work like this answer: VirtualBox Host ssh to Guest

I could not even ping the guest from the host:

PING ( 56 data bytes
Request timeout for icmp_seq 0
Request timeout for icmp_seq 1
Request timeout for icmp_seq 2
--- ping statistics ---
4 packets transmitted, 0 packets received, 100.0% packet loss

But ping works fine from guest to host, ssh from guest to localhost is also ok, the PermitRootLogin is yes, the netstat result is ok:

netstat guest

EDIT after switching to bridged mode, it works fine.

  • It's unclear what you want to achieve! Your first attempt forwards any host-vb:22 to guest:22 from the host's network. This means you can't reach host from other hosts in the host-vb network (probably Is this your aim?
    – klanomath
    Apr 20, 2016 at 1:35
  • I want to ssh to my guest OS, i've tried without port forwarding, it failed, with port forwarding also failed, but when I switch to bridged mode it works fine.
    – Kokizzu
    Apr 20, 2016 at 2:11
  • Unless you were running VirtualBox as a privileged user it shouldn't allow you to use host's port 22. You should use a higher number like in the example you linked to.
    – techraf
    Apr 20, 2016 at 3:05

1 Answer 1


After adding a port-forwarding rule (e.g. SSH TCP 2222 22) enter in the host's Terminal.app:

 ssh user_name@host-ip -p forwarded_port

Example with the rule above:

 ssh [email protected] -p 2222

Don't use identical ports in the rule (host's port ≠ guest's port) like in your screenshot. user_name has to be the name of a remote access enabled account on the guest OS.

You may even skip the IP addresses ( and in the rule and either use:

 ssh [email protected] -p 2222


 ssh [email protected] -p 2222

or even

 ssh user_name@localhost -p 2222
  • Please disregard the edit that I made anonymously, which noted that one may also use: ssh user_name@localhost -p 2222
    – JDQ
    Jan 4, 2018 at 7:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .