Thursday, 15 August 2013

Install a SMB server on Raspberry Pi

First Samba needs to be installed, to do this type:

sudo apt-get install samba

Then we want to install various helper tools. Do this by typing:

sudo apt-get install samba-common-bin

Before we can run the SMB server we need to make some configurations to it. First we need to configure access for some user(s). I personally like to have two users that is only used to access the SMB server. One with read/write access, and one with read access only. Do this by running the following commands:

sudo useradd -M usbowner
sudo passwd usbowner
sudo useradd -M usbguest
sudo passwd usbguest

This will create a two users. One named usbowner and one named usbguest. The -M switch is to prevent a home directory from being created.

My SMB path is a USB drive mounted at /media/USB. Now we need to make usbowner the owner of /media/USB. To do this type:

sudo chown -R usbowner:usbowner /media/USB/

Also ensure that usbguest has read but not write access rights.

Now that we have our users configured, we can start to change the smb.conf file.

sudo nano /etc/samba/smb.conf

Then i would comment out the following lines by adding a ; to the front of the item as this makes initial setup and testing easier.
; comment = Home Directories
; browseable = no
; create mask = 0700
; directory mask = 0700
; valid users = %S
; comment = All Printers
; browseable = no
; path = /var/spool/samba
; printable = yes
; guest ok = no
; read only = yes
; create mask = 0700
; comment = Printer Drivers
; path = /var/lib/samba/printers
; browseable = yes
; read only = yes
; guest ok = no
; comment = Samba server's CD-ROM
; read only = yes
; locking = no
; path = /cdrom
; guest ok = yes
; preexec = /bin/mount /cdrom
; postexec = /bin/umount /cdrom

Then at the end of the file add
comment = raspi
path = /media/USB
valid users = usbowner usbguest
browseable = yes
public = no
writable = yes

Then run:

sudo smbpasswd -a usbowner
sudo smbpasswd -a usbguest

to add those two users to smbpasswd file

Then finally restart the samba service by typing:

sudo service samba restart

No comments:

Post a Comment