SSH and file sharing with guest operating system

I’m a big fan of Apple products. I really like the OS X operating system, and I love the hardware on which it runs. I also love that OS X is built on a UNIX core, which complements the graphical interface with a solid command-line interface that runs a lot of scientific and open-source software out-of-the-box. However, some of the scientific tools I use are difficult (if not impossible) to configure, program, and run without a Linux operating system. So my solution for several years has been to run a Linux virtual machine via VMware or VirtualBox on my Apple hardware. When I need the Linux environment (which is most of the time), I fire up the Linux guest OS and get to work. Despite how far Linux GUIs have come, however, I still prefer OS X for web browsing, Skype, and just about anything else that doesn’t involve the command line.

This week I decided that I would invest some time figuring out how to interact with my guest OS (Linux) while staying completely in my host OS (Mac OS X)–essentially treating my guest VM as a remote machine. Essentially, this amounted to two tasks: opening up shell access and exposing the file system.

Shell access

Enabling shell access was pretty simple. On the guest side, all I had to do was install OpenSSH (sudo apt-get install openssh-server for Debian-based distros). On the host side, I simply had to create a host-only network in VirtualBox and edit my VM’s network settings. Here’s exactly what I did.

  • In VirtualBox, open Preferences and select the Network tab
  • Add a host-only network by clicking the “+” icon, and then click ok
  • Back in the main VirtualBox menu, select the virtual machin, click ‘Settings’, and select the Network tab
  • Adapter 1 should be attached to NAT, so select Apapter 2, enable it, and attach the host-only adapter just created. Click ok

At this point, the virtual machine should respond to a ping and an SSH login attempt. Just use the ifconfig command in the guest machine to determine its IP address.

File system

I do a fair amount of coding using command-line text editors such as vim and nano. However, when I’m coding for hours and hours, I do prefer using a graphical interface, so being able to open files on the guest machine (Linux) with a text editor on my host machine (OS X) required some file sharing. VirtualBox provides some extensions to facilitate file sharing from the host to the guest, but what I want required sharing the other way around–from guest to host.

I ended up installing the Samba file sharing service. I followed the instructions in these tutorials (here and here) pretty closely, so rather than rehashing those points I’ll just leave the links.

Once Samba was up and running, I was able to connect by opening Finder, selecting “Connect to server” (command-K), and then entering smb:// followed by the guest machine’s IP address.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s