[object Object]

How to enable Samba sharing in Ubuntu

How-to written and screenshots taken on 2020 March 6

In Windows it's easy to get file sharing to work. At least I can make it work all the time. Part of it is the graphical interface, but file sharing in Linux, in my case Ubuntu has it's peculiarities. Even if you use the Ubuntu GUI tools, it doesn't always work. It has cost me countless hours over the years and every time I have to reconfigure Samba I'm in hell. So this is my guide on how to enable Samba sharing in Ubuntu.

In this example we have the server user joediapna, two actual people diana and joep and a shared (somewhat public) computer account in the living room discobal.

1. Prepare

  1. List the folders or volumes you want to share. I want to share two volumes, or to be more precise a single folder in each volume. The Workspace volume is where for example software installers are shared and it has private folders for the "real" users. The second volume Data is used to share data between all computers. I want the server to be the owner of all volumes/data, except the private folders.

    One more thing: the sharename cannot have the same name as the folder it represents! It is however case-sensitive so Data is not the same as data.

Folder / volumeSharenameOwner
/mnt/Data/dataDatajoediapna
/mnt/Workspace/workspaceWorkspacejoediapna
/mnt/Workspace/Diana-diana
/mnt/Workspace/Joep-joep
  1. List groups and permissions. To make life easier, I'll group users together in two groups. The first group joediapna can read and write anywhere (except the private folders). The sambashare group can only read anywhere (except the private folders). We need the x to build the tree of subfolders.
GroupSharenameOwner
/mnt/Data/dataPermissions
Data
Permissions
Workspace
joediapnarwx / 7rwx / 7
sambasharer-x / 5r-x / 5
other usersr-x / 5r-x / 5
  1. List the users. We have 4 users split into 2 groups.
UserTypeGroup
dianaAdminjoediapna, sambashare
dianaAdminjoediapna, sambashare
discobalUsersambashare
joediapnaOwnerjoediapna, sambashare
joepAdminjoediapna, sambashare

2. Permissions

  1. Mount the volumes you want to share. To mount volumes at least you should make the mount points (folders) and mount the volume. I have ZFS volumes which should mount automatically after every reboot. I haven't tested that yet. If you are mounting other folders, you have to add them to /etc/fstab. Please Google for that.

    sudo mkdir /mnt/Data
    sudo mount Data /mnt/Data
    sudo mkdir /mnt/Workspace
    sudo mount Workspace /mnt/Workspace
  2. Check with ls -l for current owner and permissions.

    cd /mnt/Data
    ls -l
  3. Data: The owner should be joediapna:joediapna and the permissions should be drwxrwxr-x (775). With these permissions the owner (the user joediapna) can do everything, the group joediapna can read and write. All other users can only read. We are going to apply these permissions on all the files and folders.

    sudo chown -R joediapna:joediapna /mnt/Data/data
    sudo chmod -R 775 /mnt/Data/data

    Folder permissions of /mnt/Data/data

  4. Workspace: The owner should again be joediapna:joediapna and the permissions should also be drwxrwxr-x (775). We are not going to apply these permissions on all the files and folders.

    cd /mnt/Workspace
    ls -l
    sudo chown joediapna:joediapna /mnt/Workspace/workspace
    sudo chmod 775 /mnt/Workspace/workspace

    Folder permission of /mnt/Workspace/workspace

  5. Now go in one level deeper and check for each folder what the permissions should be. Apply them for each folder recursively.

    cd /mnt/Workspace/workspace
    ls -l
    sudo chown -R joediapna:sambashare /mnt/Workspace/workspace/download
    sudo chmod -R 775 /mnt/Workspace/workspace/download
    sudo chown -R joep:joep /mnt/Workspace/workspace/joep
    sudo chmod -R 700 /mnt/Workspace/workspace/joep

    Folder permissions of Workspace folders

3. Users and groups

  1. Create groups. The joediapna group already exist as it was made with the initial user during setup of Ubuntu. We only have to make the sambashare group.

    sudo groupadd sambashare
  2. Create users. We do have to create 3 users: diana, discobal and joep. This is the example for the first.

    sudo useradd -m diana -p PASSWORD
    sudo usermod -L diana
    sudo usermod -a -G joediapna diana
    sudo usermod -a -G sambashare diana

4. Install and configure Samba

  1. Install Samba:

    sudo apt update
    sudo apt install samba
  2. Open the file Samba configuration file:

    sudo nano /etc/samba/smb.conf
  3. Change the workgroup to your Windows workgroup if you have one. I have called it BALZAAL.

    # Change this to the workgroup/NT-domain name your Samba server will part of
    workgroup = balzaal
  4. Scroll all the way to the bottom and add the shares.

    [Data]
    path = /mnt/Data/data
    browseable = yes
    writeable = yes
    create mask = 0775
    directory mask = 0775
    guest ok = no
    [Workspace]
    path = /mnt/Workspace/workspace
    browseable = yes
    writeable = yes
    create mask = 0775
    directory mask = 0775
    guest ok = no
  5. Save and close by pressing Ctrl-O to save and Ctrl-X to close. Now restart Samba.

    sudo service smbd restart
  6. Add a rule in the firewall to allow Samba traffic.

    sudo ufw allow samba

5. Now the peculiar part

  • The Samba user passwords aren't the same as the system users we just created. I always forget that. We have to add that password to Samba too. So for each user:

    sudo smbpasswd -a diana

6. Check installation

  1. If everything went right, which it never does in my experience, you should now be able to browse these shares. From a Unix machine (Mac or Linux) type smb://xxx.xxx.xxx.xxx/Data or from Windows: \\xxx.xxx.xxx.xxx\Data.

  2. If it doesn't work... First check if Samba is installed and running:

    smbd --version
    systemctl status smbd
    systemctl status nmbd
  3. If yes, try to restart the Samba service:

    sudo systemctl restart smbd
    sudo systemctl restart nmbd
  4. Then install a small Samba GUI. It's a GUI, so you can only run it through VNC. See if you see anything strange there.

    sudo apt install system-config-samba
    sudo system-config-samba
    sudo touch /etc/libuser.conf