January 05, 2024

Samba, RPi as Windows file/print server

Updated 2024-01-05 OK with Bookworm !

If You want that the Raspberry Pi(RPi), shall appear in MS File Explorer or Mac Finder, as a File server, the easiest way is to install Samba.

This also makes it much easier if You want to edit files on the RPi with editors from Your MS/Apple device. Or maybe moving files from/to the RPi.


Intro
This setup can also be used when you want to share a RPi USB connected storage in the network.

Installing
Log on to the RPi and update

$ sudo apt update


then install Samba

$ sudo apt install samba

Edit the Samba configuration file so that You have more than "Read Only" rights.

$ sudo nano /etc/samba/smb.conf

Then find the following part 

#======================= Share Definitions =======================

[homes]        
    comment = Home Directories
    browseable = no

# By default, the home directories are exported read-only. Change the
# next parameter to 'no' if you want to be able to write to them.

    read only = yes      

so change to

read only = no

Printserver
If you are planning to use the RPi as a print server find the following part  

# Windows clients look for this share name as a source of downloadable
# printer drivers

[print$]
   comment = Printer Drivers
   path = /var/lib/samba/printers
   browseable = yes
   read only = yes
   guest ok = no

and change to

read only = yes
guest ok = yes

and then save the file.

Add user
If you intend to use an existing RPi/Linux user, maybe "pi"?, just use the following command to add "pi" as a Samba user and set a password (The command "smbpasswd" has been replaced by "pdbedit")

$ sudo pdbedit -a pi
new SMB password:
retype new SMB password:
............

Restart the Samba service

$ sudo systemctl restart smbd

and now You should be up and running and the pi home folder should be shared

The picture above is from a Mac browsing a RPi running Homebridge and 2 plugin

Other user commands

List the Samba users sudo pdbedit -L

Delete Samba user  sudo pdbedit -x pi


Apache share
The RPi is also running an Apache server and therefore I wanted to share its default folder. Adding the following to the configuration file


[Apache_folder]
   comment = Apache folders
   read only = no
   locking = no
   path = /var/www/html/
   guest ok = no

And adding the default Apache user 

$ sudo pdbedit -a www-data
New SMB password:
Retype new SMB password:
Added user www-data.
$ sudo systemctl restart smbd

This makes it easy to edit the files if You log on to the RPi, from Your Mac/PC, with the "
 
www-datauser.

2 comments:

  1. Tack för suveräna guider!
    Jag är nybörjare på raspberry och när jag ansluter till min raspberry med samba på min mac så ser jag inte allt på den. Jag kommer till exempel inte åt min config.json för homebridge. Gissar att det har något med rättigheter att göra, men vet inte hur jag ska ändra dem?

    ReplyDelete
  2. Tjing !
    Tror det beror på vem du loggar på med, default är guest. logga på med pi så lär du komma rätt, hls Mats

    ReplyDelete

Feel free to leave a comment ! ... but due to a lot of spam comments I have to moderate them. Will reply ASAP !