In this guide, we are going to show Linux users how to install and configure Samba for sharing files on Linux Mint. Samba is an open-source implementation of the Server Message Block (SMB) and Common Internet File System (CIFS) protocols that provides file and print services between clients across various operating systems. Samba makes it possible to share files between Linux and Windows operating systems. In our case here, Linux Mint will be Samba server.

Install Samba on Linux Mint

We start by installing required samba packages on Linux Mint. This is done using apt command line package manager.

sudo apt-get -y update
sudo apt-get -y install samba vim

Configure Samba share on Linux Mint

Samba configuration file is located in /etc/samba/smb.conf. Any changes made to this file requires Samba daemon to be restarted. Let’s start by creating a directory to be shared with Samba. The directory must exist before it can be configured in smb.conf. Let’s create one under /home and allow it to be readable and writable by all users.

sudo mkdir -p /home/share
sudo chmod 777  /home/share

Now open Samba configuration file to make the necessary changes.

sudo vim /etc/samba/smb.conf

Ensure you have the content as shown under global settings.

Vim usage:

  • Press ‘i‘ to enter insert mode to edit the file.
  • Press ‘esc‘ to exit insert mode.
  • Enter ‘:wq‘ to save and quit.
[global] 

# Configure correct UTP 
  unix charset = UTF-8 
# Change this to the workgroup/NT-domain name your Samba server will be part of 
  workgroup = WORKGROUP 
  server min protocol = NT1
  ntlm auth = yes
  #interfaces = 127.0.0.0/8 eth0 
  bind interfaces only = yes 

# Set share configuration at the end 
[Docs] 
  path =  /home/share
  writable = yes 
  guest ok = yes 
  guest only = yes 
  create mode = 0777 
  directory mode = 0777

Configuration details:

  • Docs – Samba share name
  • path = /home/share – Directory to share
  • guest ok = yes – Turn on guest share
  • guest only = yes – All protected as guests
  • writable = yes – Set share directory as writable
  • create mode = 0777 & directory mode = 0777 – Allow access to all

Configure Secure Samba Share

We need to give group ownership to Samba shared directory to sambashare group:

sudo chgrp sambashare /home/share

Now create samba share user, replacing user1 with your user name:

sudo useradd -M -d /home/share/user1 -s /usr/sbin/nologin -G sambashare user1
sudo mkdir /home/share/user1
sudo chown user1:sambashare /home/share/user1
sudo chmod 2770 /home/share/user1
sudo smbpasswd -a user1
sudo smbpasswd -e user1

We created a user’s home directory inside Samba share parent directory and set ownership to the samba share group. Let’s create another user.

sudo useradd -M -d /home/share/smbadmin -s /usr/sbin/nologin -G sambashare smbadmin
sudo mkdir /home/share/smbadmin
sudo smbpasswd -a smbadmin
sudo smbpasswd -e smbadmin
sudo chown smbadmin:sambashare /home/share/smbadmin
sudo chmod 2770 /home/share/smbadmin

Configure secure sambashare

Open samba configuration file and add the following contents:

sudo vim /etc/samba/smb.conf

Add the following content at the end of the file:

[user1]
path = /home/share/user1
readonly = no
Browseable = yes
force create mode = 0660
force directory mode = 2770
valid user = @user1 @sambashare
[smbadmin]
path = /home/share/smbadmin
readonly = no
Browseable = no
force create mode = 0660
force directory mode = 2770
valid user = @smbadmin @sambashare

Save the file and restart Samba daemon

sudo systemctl restart smbd nmbd

Allow Samba through the firewall

sudo ufw allow samba

Configure Samba client

To be able to access Samba share directory from another machine, we need to install Samba client. I am going install Samba client on Elementary OS.

sudo apt-get install samba-client cifs-utils

To access Samba share temporarily, run the command with syntax as shown below:

smbclient //sambaserver-ip/share-dir -U sambauser

For example in my case:

smbclient //192.168.1.208/gedion -U gedion
How To Configure Samba File Sharing on Linux Mint 22 01

Mount the Samba share to a directory for permanent access:

sudo mkdir -p /mounts/shares
sudo mount -t cifs -o username=user1 //192.168.1.208/user1 ~/mounts/shares

Check if the directory is mounted on the client:

$ df -h

Output should be as shown:

How To Configure Samba File Sharing on Linux Mint 22 02

To enable persistent mount even on reboot, mount the samba share in fstab file

sudo vim /etc/fstab

Add the following line depending on your mount point.

//server/share /mountpoint cifs username=user1,password=user1_password,uid=user1,gid=user1 0 0
## For Example
//192.168.1.208/gedion /mnt/shares cifs username=gedion,password=Xcqt0689,uid=gedion,gid=gedion 0 0

Create the /mnt/shares directory the mount it:

$ sudo mkdir -p /mnt/shares 
$ sudo mount -a 
$ df -hT | grep cifs
//192.168.1.208/gedion cifs    39G   14G   26G  35% /mnt/shares

You have successfully set up Samba file share on Linux Mint and mount the shared directory on a client. Check more guides below:

1 COMMENT

  1. trying to follow this as new user and, well it’s near impossible.
    you say to edit the smb.conf file. I enter the command you say but it won’t let me add or edit anything so how can I add the info if I can’t type anything?
    have not bothered with the rest of the tut as if I can’t add to the smb.conf file I guess the rest is moot
    would be nice if you had included HOW to add/edit the smb file for beginners.

    • Hi, we are sorry for that, we know it can be very frustrating to use vim, especially it you are a beginner. We apologise for that. In response to this, please check the guide again, we have updated in with explicit instructions, thank you.

LEAVE A REPLY

Please enter your comment!
Please enter your name here