Installing samba on linux guest machine

Published on 15 May 2021

A couple months ago, I had this one weird problem running autoreload for my sphinx installation. The sphinx folder was on my Windows 10 host, and the autoreload was run on Fedora guest virtual machine through the shared folder feature on VirtualBox. The error was something related to file system, which was beyond my ability to trace the to fix. I decided to move that sphinx folder into Fedora (now outside the shared folder), which means I would not have a direct and convenient access anymore into the folder.

How to get around that? Network file sharing with samba (SMB) protocol. The idea is that I have samba running on my Fedora guest with a shared folder exposed through it, and then connect to that shared folder on my Windows 10 host.

The networking

I first tried using NAT adapter and planning to port-forward through the VirtualBox, that did not work. What worked was having 2 adapters for the guest machine: NAT for the first adapter and Host-only for the second adapter. In the past, this 2-adapter configuration did not quite work for me, but this time it worked so… I find that quite interesting.

Guest machine - 2-adapter setting

Initial installation and configuration

First, install samba package. It runs, by default, on port 139. For setting up the networking with the aforementioned 2-adapter configuraiton, there are 2 parts:

  1. Setting up the host-only adapter through the VirtualBox interface.
  2. Changing the adapter properties through Control Panel > Network and Internet > Network Connections on the Windows host.

For part 2, ensure the IPv4 properties for the “VirtualBox Host-Only Network” adapter is enabled and has the following settings for “IP address section”

Windows 10 host adapter configuration

# IP address:
192.168.56.1

# Subnet mask:
255.255.255.0

On VirtualBox Manager, for Network section, ensure the VirtualBox Host-Only Ethernet Adapter is active. Then, boot up the VM, and check if it is active or not (with ifconfig command).

VirtualBox network manager

This returned enp0s3 with the address 10.0.2.15 (this is NAT) and enp0s8 with the address 192.168.56.101 (this is Host-only). Then, test internet connection (through NAT) by pinging some website on the internet.

Samba configuration on guest OS (VM)

First, back up the default config file, and then create a new config file:

# Back it up
sudo mv /etc/samba/smb.conf /etc/samba/smb.conf.fedora0

# Create a new configuration
cat > /etc/samba/smb.conf << EOF
[global]
  wins support = yes
  server role = standalone server
  security = user

[public]
  path = /home/aixnr/repo
  comment = Fedora Local Git Repo
  read only = No
  browseable = yes
  writeable = yes
  valid users = aixnr
EOF

The systemd service file for Samba is smb. Then, add a $USER to Samba

sudo smbpasswd -a $USER

If $USER is not specified, it will assume root, because sudo. Not recommended.

Adding share on Windows 10 host

Right click anywhere on This PC, choose Add a network location, then Choose a custom network location, then add the following address:

\\192.168.56.101\public
  • The address here corresponds to the guest’s IP address.
  • The \public there corresponds to the name of the shared folder as defined in the [public] section inside the smb.conf configuration file.

That’s it.