How to ssh into CentOS 7/8 VirtualBox VM from MacOS
I have installed a CentOS 7 VM from osboxes.org on Oracle VirtualBox on my Mac. I need to be able to ssh into the VM from the Mac. I have tried to search on the net, but was unable to find information for this set-up - could find some youtube videos, but they talked about Windows.
Some articles talk about defining Bridged Adapter, some NAT or host-only or some combinations of these but no consistency amongst them.
Where can I find detailed set-up information that will allow me to ssh into the VM from my Mac. I want to create the VMs to learn Ansible and Confluent tasks.
Thank you
You can either use a bridged interface or NAT.
Using bridging, the virtual NIC of CentOS will act as if connected to your real network and switch. It'll get an IP from the same IP range as your macOS host and will be fully accessible from the mac host or any other device on LAN. On VM network settings, you'll choose the virtual adapter, attached to bridge and select physical adapter on your host (normally a list will be available). If you use DHCP on your LAN, dhcp should be set on VM also. If static, change to static on VM also. Then type on host:
ssh [CentOS_user]@[CentOS_VM_IP]
Bridging using wireless interface on host is possible on recent versions of VBox, yet a bit limited. using ssh to VM should not be a problem.
Using NAT, your VM will be in a separate network, not immediately accessible from your MacOS host or other devices on your LAN. You need to forward port 22 (used by ssh) of your VM to a port on macOS host, for example 2222. On VM network settings, you'll choose the virtual adapter, attached to NAT and then click
port forwarding
button below. There on the new window, you'll forward guest's port 22 to localhost's (127.0.0.1) to port 2222 or whichever high port is available. Inside the VM, the network setting must be DHCP. Afterwards you'll just type:ssh -p 2222 [CentOS_user]@localhost
to connect.
You can follow Windows or Linux articles, the interface is almost the same on Virtualbox regardless of platform. Keep in mind the principles I mentioned above, they'll help you understand the guides.
I'm attaching a very comprehensive guide on VBox networking. It's on Windows host, you may have a more recent version of VBox, yet the principles apply. Virtualbox comprehensive networking guide