Mounting an SMB Path on Raspberry Pi or Linux Using CIFS Utilities

· 3 min read

Photo by Jainath Ponnala on Unsplash

Accessing shared folders and files over a local network can be convenient, especially when you have a Raspberry Pi or any Linux machine as part of your network. In this guide, we will walk you through the step-by-step process of mounting an SMB path on a Raspberry Pi or Linux machine using the CIFS utilities. This will allow you to access files and directories shared on other machines, such as NAS or Windows computers, in a seamless manner.

Step 1: Install cifs-utils

The first step is to install the CIFS utilities, which will enable you to mount SMB paths. Open the terminal on your Raspberry Pi or Linux machine and run the following command:

sudo apt-get update
sudo apt-get install cifs-utils

Step 2: Create a Credentials File

To securely authenticate and access the shared SMB folder, you need to create a credentials file containing the necessary login information. Follow these steps to create the credentials file:

Open a terminal and create an empty credentials file using the `nano` text editor:

nano ~/.smbcredentials

Add the following lines to the credentials file, replacing `smbuser1`, `passwordforsmbuser1`, and `WORKGROUP` with your actual SMB username, password, and domain, respectively:

username=smbuser1
password=passwordforsmbuser1
domain=WORKGROUP

Step 3: Update Credentials File Permissions

For security reasons, we need to restrict access to the credentials file so that only the owner can read and modify it. Run the following command to set the appropriate permissions:

chmod 0600 ~/.smbcredentials

Step 4: Update the Fstab Configuration

The `/etc/fstab` file contains information about filesystems and is used to automatically mount them at boot time. We will add an entry to this file to mount the SMB share. Open the `/etc/fstab` file using the `nano` text editor:

sudo nano /etc/fstab

Step 5: Add Configuration to Fstab

Assuming you want to mount the shared folder from the SMB server at `//192.168.1.12/documents` to the local directory `/home/user1/documents`, add the following line to the end of the `/etc/fstab` file:

//192.168.1.12/documents /home/user1/documents cifs credentials=/home/user1/.smbcredentials,x-systemd.automount,iocharset=utf8,rw,uid=1035,gid=100,vers=2.1 0 0

Let’s break down the options used in the configuration:

Step 6: Mount the SMB Directory

Finally, to mount the SMB share without the need to reboot, you can run the following command:

sudo mount -a

This command will mount all filesystems listed in the `/etc/fstab` file, including the newly added SMB share.

Congratulations! You have successfully mounted an SMB path on your Raspberry Pi or Linux machine. You can now access the shared folder and its contents as if they were located on your local machine, making it easier to work with files and data across the network. Remember that the mount will persist across reboots, so you don’t need to remount it manually each time. Enjoy seamless access to your shared resources!

Originally published on Medium .

← Back to blog