Linux

Creating an SMB/CIFS mount point on Linux

Mount an SMB/CIFS share on a Linux server: install cifs-utils, create the mount point, mount the volume with credentials, plus a backup script example.

· 1 min read · level: intermediate

This very practical procedure gives the steps required to mount, on a Linux server, an SMB/CIFS share coming for example from a Windows server.

Step 1: Installing the cifs-utils package

sudo apt install cifs-utils

Step 2: Create a mount point

mkdir /mnt/votre-chemin

Step 2: Mount the volume

sudo mount -t cifs -o username=votre-utilisateur //IP-serveur/votre-chemin /mnt/votre-chemin

-o is used to enter the credentials. The user name must be replaced with a user who has access to the directory of your server sharing over SMB/CIFS.

BONUS: Backup script

#!/bin/bash

wpdbdirectory=/srv/wordpress/database
wphtmldirectory=/srv/wordpress/html

echo $message

echo "Le dossier $wpdbdirectory s'apprête à être copié dans /backups"
cp -r $wpdbdirectory /mnt/backups-on-winsrv$wpdbdirectory$(date +%d-%m-%Y)

echo "Le dossier $wphtmldirectory s'apprête à être copié dans /backups"
cp -r $wphtmldirectory /mnt/backups-on-winsrv$wphtmldirectory$(date +%d-%m-%Y)

echo "Voici le résultat du dossier backups"
ls /mnt/backups-on-winsrv