Samba shares a folder so Windows, Mac and Linux computers can use it. The share is described in a config file the service reads when it starts, so you restart it after a change. The folder's group and permissions decide who may write.
Everyone in the class needs to hand in work to one place. How do you set that up?
Names and addresses· Every device on the internet has an IP address, and every packet carries the address it is going to.
File sharing is the most common job for a small server. Two things have to be right: the service has to know about the share (a config file), and the files on the Pi have to allow the right people (owners, groups and permissions from lesson 3).
How this lesson works: Predict, Try, Investigate, Modify, Practise, Make
Predict: Read the problem and decide what you think before you try anything. A wrong guess is fine: it shows you what to look for.
Try: Try it on the board and compare the result with your prediction.
Investigate: Work out why it happens, one step at a time.
Modify: Change the problem on purpose and see what happens.
Practise: A few on your own, to check you have it.
Make: Make your own problem using what you have learned. Expect a few tries; that is normal.
Make your prediction first. Help opens once you've locked it in.
PredictRead the problem and decide what you think before you try anything. A wrong guess is fine: it shows you what to look for.
No restart
TryTry it on the board and compare the result with your prediction.
Try: add a share
Was your prediction right?
Try it yourselfYour edits are saved in this browser.
Add a share called classshare to /etc/samba/smb.conf, restart smbd, then run smbclient -L localhost.
Use the board. This ticks when you get there.
InvestigateWork out why it happens, one step at a time.
Worked example: Writing to a file you do not own
Worked exampleBefore each step, say what you think comes next.
echo -e "[classshare]npath = /srv/class" | sudo tee -a /etc/samba/smb.confadd the share, as root.
sudo systemctl restart smbdmake smbd read the file again.
sudo chgrp class /srv/classthe folder belongs to group class.
sudo chmod 775 /srv/classowner and group read, write and enter; others only read.
Now try it yourself.
Sam fixes the share. Click the line where it first goes wrong.
ModifyChange the problem on purpose and see what happens.
Vary: change one thing
Try it yourselfYour edits are saved in this browser.
Make /srv/class belong to the group class.
Use the board. This ticks when you get there.
/srv/class belongs to class, but Alex still cannot save a file there. Fix the permissions.
Use the board. This ticks when you get there.
Someone set /srv/class to 777. Bob is not in class and should only be able to read. Fix it.
Use the board. This ticks when you get there.
PractiseA few on your own, to check you have it.
Practise
MakeMake your own problem using what you have learned. Expect a few tries; that is normal.
A class hand-in share
Then: on a real Pi, run testparm to check smb.conf and smbpasswd -a alex to give Alex a Samba password (Samba keeps its own).
Try it yourselfYour edits are saved in this browser.
Samba shares a folder so Windows, Mac and Linux computers can use it. The share is described in a config file the service reads when it starts, so you restart it after a change. The folder's group and permissions decide who may write. About 40 minutes.
I can add a share to Samba and restart the service.
I can use tee to write a file I do not own.
I can set a folder so a group can write and strangers cannot.
Before class
Try the boards yourselves.
The one idea: a service reads its settings at start-up, and the files it serves have owners, groups and permissions that decide who may use them.
Simplifications: the pretend smb.conf only needs [name] and path. The real one also wants read only = no, valid users = @class and a Samba password for each user (sudo smbpasswd -a alex), because Samba's passwords are separate from the Pi's. Say this before students try it for real.
Taught: Samba (works with Windows, Mac and Linux). Other options to name: NFS (file sharing between Linux computers, simpler but with no passwords), Nextcloud (a web page for files, like your own Drive, needs a web server and database), Syncthing (copies folders between computers).
With internet: sharing outside the school needs a VPN (Tailscale or WireGuard) or the files can be read by anyone who finds the port. Do not open router ports for Samba.
Running the lesson
Predict: wrong answers think the service watches its file.
Try: show the failing sudo echo version first.
Worked example: stop at 777 and ask who else it lets in.
Vary: after taking rights away, ask whether Bob is stopped from reading.
Make: ask what a real hand-in folder would also need.
The hard part (on purpose)
The sudo-and-redirect gotcha. Run the failing command so students read the error.
When students get stuck
Permission denied writing smb.conf. Ask: Are you using sudo echo with >> ? Fix: echo ... | sudo tee -a file.
The share does not appear. Ask: Did you restart smbd? Fix: sudo systemctl restart smbd.
Stretch and support
Stretch: Find out why Samba needs its own password for each user.
Support: A card with the three jobs: share, restart, group.
Where it leads
Links: Who can read what (permissions); Accounts, groups and sudo; next: Host Jellyfin.
What each step is for
no restart: Committing to when a service reads its settings tests the new move: it reads them at start-up, not every second.
Try: add a share: Adding and restarting settles the prediction.
Worked example: Writing to a file you do not own: Following the method once, then finding where a plausible account goes wrong, models the new move.
Vary: change one thing: Each task changes one thing: the group, the permission for the group, and taking rights away from strangers.
Practise: Reading modes and choosing fixes without the board is the same move in new forms, plus a review of services.
a class hand-in share: Combining the config, the restart and the group is the whole move.