In this guide, we are going to show Linux users how to install and configure Samba for sharing files on Linux Mint 20. 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 20 will be Samba server.

Step 1: Install Samba on Linux Mint 20

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

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

Step 2: Configure Samba share on Linux Mint 20

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.

[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

Step 3: Configure Secure Samba Share (Recommended Way)

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 = no
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

Step 4: 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.100.77/user1 -U user1

Mount the Samba share to a directory for permanent access.

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

Check if the directory is mounted on the client

$ df -h

Output should be as shown:

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.

//192.168.100.77/user1  /mnt/shares cifs credentials=/.sambacreds 0 0

Save the file and exit the create the credentials file.

$ sudo vim /.sambacreds

Add the credentials information

username: user1
password: yourpassword
domain: WORKGROUP

Confirm if mounted

$ sudo mkdir -p /mnt/shares 
$ sudo mount -a 
$ df -hT | grep cifs
//192.168.100.77/user1 cifs      20G  14G  6.3G  69% /mnt/shares

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

Linux Learning courses:

$15.20
$151.98
in stock
Udemy.com
(12646)
$15.20
$151.98
in stock
Udemy.com
$15.20
$151.98
in stock
Udemy.com
$15.20
$151.98
in stock
Udemy.com
$16.37
$163.68
in stock
Udemy.com

LEAVE A REPLY

Please enter your comment!
Please enter your name here

5 × four =