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 10.0.0.10, guest 10.0.2.15) 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 10.0.2.15 (10.0.2.15): 56 data bytes
Request timeout for icmp_seq 0
Request timeout for icmp_seq 1
Request timeout for icmp_seq 2
^C
--- 10.0.2.15 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 10.0.0.0/24). Is this your aim? – klanomath Apr 20 '16 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 '16 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 '16 at 3:05

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

 ssh user_name@host-ip -p forwarded_port

Example with the rule above:

 ssh user_name@10.0.0.10 -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 (10.0.0.10 and 10.0.2.15) in the rule and either use:

 ssh user_name@10.0.0.10 -p 2222

or

 ssh user_name@127.0.0.1 -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 at 7:32

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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