This is a short, somewhat introduction, post on how to share a Raspberry Pi directory on a local area network (LAN) and will conclude with how to connect to this directory using Linux-based and Windows-based operating systems. Sharing will be done by using the Linux package Samba, which can be easily installed onto a Raspberry Pi running Raspbian.
The shared directory can be any accessible directory on the Raspberry Pi itself (e.g. a local directory, USB mount, etc.). In order to make this process somewhat more usable (especially between different operating systems), the share directory will be without privileges and will be fully accessible to all users on the LAN.
Assumptions & requirements
A fully working, networked Raspberry Pi with the latest/updated version of Raspbian and sudo rights. Everything here will be explained by using the terminal. Although a static IP is not required to share the directory to Windows, it is recommended to gain access from another Raspberry Pi (Linux). If not connected to a screen with a keyboard and mouse, this process can also be done by using PuTTY.
The shared directory
The shared directory can be any directory on the Raspberry Pi itself. Here the
/home/pi/share directory will be used.
To create this directory, use the
/home/pi is the working directory and
share is the shared directory.
User permissions (or user rights) add extra security to files and directories. Directories can be made readable, writable and/or executable. For the shared directory these permissions can be changed according to need.
To makes things easy and give full privileges to the shared directory use:
sudo chmod -R 777 /home/pi/share
This will also set the GID for the directory. Similarly, use:
sudo chmod 777 /home/pi/file-name.sh
to change permissions for a specific file.
A workgroup is a group of computers on a local network that can access each other’s directories. Samba is perfect for managing this (see below). A new workgroup can be created, or the name of an already created workgroup can be used. The default workgroup created by Microsoft Windows is usually WORKGROUP, so this one will be used.
To share a directory from a Raspberry Pi to a LAN, Samba will need to be installed and properly configured. Samba contains the SMB protocol, support for the Windows naming service (WINS) and support for joining Windows workgroups.
To download Samba:
sudo apt-get install samba sudo apt-get install samba-common-bin
It is recommended to make a backup of the original samba configutation file:
sudo cp -p /etc/samba/smb.conf /etc/samba/smb.conf.original
To edit and configure the Samba configuration file:
sudo nano /etc/samba/smb.conf
The ==Global Settings== section ([global]) is divided into various subsections.
In the ## Browsing/Identification ### section, change and activate the following lines (remove # where needed and add):
workgroup=WORKGROUP wins support=yes netbios name=hostname
workgroup=WORKGROUP sets the workgroup of the users that are allowed access.
wins support=yes (default no) allows the Raspberry Pi to be accessed by using the netbios name from windows based systems.
netbios name=hostname is the name the shared directory will be broadcasted as on Windows systems. The hostname can be obtained by using
hostname in the terminal.
Then way down at the bottom of this file, in the ==Share Definitions== section, shared directories can be added as follows:
[PiShare] comment=Raspberry Pi Share Directory path=/home/pi/share browseable=yes guest ok=yes read only=no create mask=0777 force create mode=0777 directory mask=0777 force directory mode=02777 force user=pi
[PiShare] is the share directory mounting name, this will share this directory as 192.168.1.xx/PiShare or \hostname\PiShare where 192.168.1.xx is the IP address of the sharing Raspberry Pi.
comment=Raspberry Pi Share Directory is the description of the share directory.
path=/home/pi/share is the absolute path to the local shared directory
browseable=yes (yes/no) makes the shared directory visible using net view.
guest ok=yes (yes/no) allow guest (anonymous) access without authentication.
read only=no (yes/no) allow users to create or edit files.
create mask=0777 -> default is 0755
force create mode=0777
directory mask=0777 -> default is 0755
force directory mode=02777
These 5 lines will enable everyone in the workgroup to create directories and files in the shared directory. It will also set the authors of these files and directories to ‘pi’.
Save on exit (Ctrl + X then Y).
Reboot the Raspberry Pi (
See the official configuration file for the Samba suite for more information.
Testing, start and/or stop Samba
To see what Samba is doing use:
service samba status
If Samba is not running, it can be activated by:
sudo service samba start
or to stop Samba use:
sudo service samba stop
After activation, Samba should start automatically after every reboot. To remove Samba from the boot sequence use:
sudo update-rc.d -f samba remove
This will not stop Samba, but will prevent it from running on reboot. To add Samba back to the boot sequence use:
sudo update-rc.d samba defaults
To view the Samba shares for a user, use:
Connecting to the shared directory
Once the Samba service has started, the shared directory can be accessed from other computers on the LAN.
If used correctly, the Raspberry Pi share should show up under the networked systems on the LAN.
\\hostname\sharename can also be used in a files explorer (internet browsers will probably not work) to access the shared directory directly. The hostname should be similar to the netbios name used in the Samba configuration file.
Linux (incl. Raspbian)
A list of the shared directories on the LAN can be obtained from another system by using:
smbclient -L hostname -U username
where hostname is the hostname or IP of the sharing Raspberry Pi and username is the username of the connecting Raspberry Pi. By using the settings above, anyone in the workgroup will have access to the share.
If the command does not work, smbclient can be installed by using:
sudo apt-get install smbclient
From a Linux file manager try
To mount a shared directory through the terminal the sharing Raspberry Pi’s IP address will be required and CIFS utilities needs to be installed. A static IP address will be very handy for continual mounts. To configure a static IP see set up a static IP address on the Raspberry Pi or set up a static IP address on the Raspberry Pi using Wi-Fi.
To install CIFS utilities use:
sudo apt-get install cifs-utils
To get the sharing Raspberry Pi’s IP address(es) use:
The mount command is:
sudo mount -t cifs //192.168.1.xx/PiShare /mnt/share -o password=
where 192.168.1.xx is the IP for the sharing Raspberry Pi,
PiShare is the share name configured earlier, and
/mnt/share is the mounting directory on the host Raspberry Pi.
To unmount the share from user side use
sudo umount /mnt/share
Mount at boot
To automatically mount a shared folder during the boot sequence of Raspbian, the mounting command can either be added to Crontab or the
To add the mount command to the
rc.local file use:
sudo nano /etc/rc.local
and add the mount command to the bottom of the file.
For Crontab, use:
@sudo mount -t cifs //192.168.1.xx/share /mnt/share-folder -o password=
Errors & solutions
Host is down error
Lately, while trying to use the Samba mount command, the following error is displayed:
mount error(112): Host is down
The Host is down error is likely to occur after a certain package update which needed the version to be defined. Defining an earlier version, (vers 1.0 in this case), will solve this problem:
sudo mount -t cifs //192.168.1.xx/share /mnt/share-folder -o vers=1.0,password=
Note the comma between the options.