3 min read

Setting Up SSH And Shared Folders in A RHEL VirtualBox VM

I discovered recently that RHEL has a free developer license, something that could have saved me a lot of trouble if I'd known it earlier. Since I do a lot of work in RHEL I've wanted to have a virtual environment that mimics it - I had been working in WSL, but I think having to work with VirtualBox VM does a better job of replicating the experience of working on it in production.

You'll need to get a RHEL Developer License to download the necessary ISO image. You can pretty much roll with the default settings while creating the VM, but two slightly trickier things for me were being able to ssh into the VM and get read-write access from the VM to a folder on my host machine.

Mounting a Shared Folder

To get a shared folder to mount, you need to "Insert the Guest Additions CD Image" with your VM running - apparently this is required for access to host folders and RHEL doesn't have this functionality enabled by default.

Once this is done, you may need to restart the machine, but you should be able to mount a shared folder to your destination of choice:

This will create a vboxsf group that gets ownership over shared folders: make sure to sudo usermod -aG vboxsf {my_username} so you can access them.

Setting Up SSH Access

Change your VM's network settings to "Bridged Adapter".

Get your IP address with ifconfig -a: it should be right beside the first inet value.

Create a key on your local machine:

ssh_keygen

Make sure to sudo chmod 600 {keyfile} - the default permissions are too open and will be ignored by your VM.

If you so desire, add it to ~/.ssh/config:

Host rheldev
HostName {your_IP}
user {your_user}
IdentityFile ~/.ssh/{your_ssh_key}

Now cat ~/.ssh/{your_ssh_key}.pub} and copy the output.

Inside your VM, create an ssh folder:

mkdir ~/.ssh

And add your public key to ~/.ssh/authorized_keys with your terminal editor of choice. Bing bang boom, you should be able to ssh rheldev without any trouble from your host terminal.

Sources

mount gives unknown filesystem type ‘vboxsf’
I’m getting an error message mount: unknown filesystem type ‘vboxsf’ when trying to mount a shared folder on my guest Ubuntu machine. I have a Windows 7 machine running 4.1.22V Oracle VM VirtualB…
ssh “permissions are too open”
I get the following error from ssh: Permissions 0777 for ‘/Users/username/.ssh/id_rsa’ are too open. It is recommended that your private key files are NOT accessible by others. This private key wil…

VSCode Remote Development With VirtualBox