Skip to Content
All memories

Samba file sharing server

 — #samba#linux

Samba is the Linux implementation of the SMB/CIFS file sharing standard used by Windows PCs and Apple computers, and widely supported by media streamers, games consoles and mobile apps.

First things first we’re going to update our repository index, make sure our operating system is fully updated, and install Samba using apt-get. Open a Terminal and type:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install samba samba-common-bin

Create your shared directory

We’re going to create a dedicated shared directory on our Pi’s micro SD hard disk. You can put it anywhere, but ours will be at the top level of the root file system.

sudo mkdir -m 1777 /share

This command sets the sticky bit (1) to help prevent the directory from being accidentally deleted and gives everyone read/write/execute (777) permissions on it. Configure Samba to share your new directory

Edit Samba’s config files to make the file share visible to the Windows PCs on the network.

sudo nano /etc/samba/smb.conf

In this example, you’ll need to add the following entry:

Comment = Pi shared folder
Path = /share
Browseable = yes
Writeable = Yes
only guest = no
create mask = 0777
directory mask = 0777
Public = yes
Guest ok = yes

This means that anyone will be able to read, write, and execute files in the share, either by logging in as a Samba user (which we’ll set up below) or as a guest. If you don’t want to allow guest users, omit the guest ok = yes line. Create a user and start Samba

Before we start the server, you’ll want to set a Samba password.

sudo smbpasswd -a pi

Then set a password as prompted. Finally, let’s restart Samba:

sudo /etc/init.d/samba restart

From now on, Samba will start automatically whenever you power on your machine.