Accessing a Windows network share from a Raspberry PI


To access a Windows-based ( CIFS ) network share from a Raspberry PI you must first have a local folder setup on your PI to act as the "mount point". Once the share has been mounted this is where you'll access the shared folder.

sudo mkdir /LOCAL/PATH

Replace /LOCAL/PATH with your choosen path. e.g. /mnt/exampleshare or /home/pi/exampleshare.

The mount command

To access a network share it must be "mounted" to a location on your local file system (the folder you created above). The command to use for this is as follows...

sudo mount -t cifs -o username=USERNAME,password=PASSWORD //SERVER/PATH /LOCAL/PATH
  • cifs is the type of mount. cifs is what Windows-based network shares typically use.

  • Enter the USERNAME and PASSWORD if the network share requires it. If not remove username=USERNAME,password=PASSWORD from the command.

  • //SERVER/PATH is the path to the network share. Could be a hostname or IP, like //192.168.1.30/exampleshare.

  • /LOCAL/PATH is the local path of your mount point (the folder you created above).

Once created, access your network share by just changing to the local mount folder and then ls the contents...

cd /LOCAL/PATH
ls

Job done (hopefully).

However, this is a one-off thing. The network share will only remain mounted for as long the device is powered up. When it's shutdown or rebooted the mounting is removed and the command above will have to be run again. This might be fine if you only need to access the network share every so often, but if not read on to automatically re-mount the network share after every reboot...

Auto-mount after every reboot

To automatically mount to a network share after the Raspberry PI has been rebooted, you need to do the following...

Edit the /etc/fstab file...

sudo nano /etc/fstab

Add line at the bottom of the file similar to the following...

//SERVER/PATH /LOCAL/PATH cifs defaults,rw,username=USERNAME,password=PASSWORD 0 0

You can test to make sure this is valid and working by running the following...

sudo mount -av

If you receive errors here something is probably wrong and it likely won't work during the next reboot.

If all is okay, reboot RPI...

sudo reboot

Then check to make sure the share has been mounted automatically after the reboot.

Enabling "Network at Boot"

In order for mounting during boot to work correctly you must ensure the RPI has the "Network at Boot" setting enabled.

To do this, go to the RPI config...

sudo raspi-config

Then...

  • Select: System Options
  • Then select and enable: Network at Boot

If necessary reboot your RPI again...

sudo reboot

Related Articles

If your PI isn't feeling well or it just needs a health check, this is how to read its current temperature.

Raspberry PI, Linux

A few examples of using crontab to setup some scheduled tasks.

Raspberry PI, Linux

A quick and simple HTTP server in Python in only a few lines of code.

Raspberry PI, Python

How to keep your instance of Pi-Hole up-to-date.

Networking