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.
Open these in Waypoints Prepare with one click. To share a file another way, copy its address and paste it into Load URL, or download the file and import it. In Prepare, the worksheet's Teacher edition shows the answers; the student copy hides them.
WorksheetOpen in PrintDownload Print the student copy; the Teacher edition has the answers.
Students will be able to
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.
Timing
Predict and Try 8 min · Worked example 10 min · Vary 10 min · Practise and Make 12 min
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.
In class
On the slides at these points. Students can do the whole lesson on their own; these are for the room. In the deck, the Run, Modify and Make slides have the live playground in them (the tutorial link is the backup), and the notes above are in each slide's speaker notes.
Think, pair, share(start) Thirty students need to hand in work to one place. Who should be able to do what?
Who may add files? Who may only read?
What would stop strangers?
Group members write; others read or nothing.
Who writes?(predict, 4 min)
Draw the folder and three people: Alex (class), Bob (not in class), a stranger. Mark who may read and who may write.
Group write; others read at most.
Restart(investigate) You edited smb.conf. What now? Restart smbd It reads its settings at start.
The hard part (on purpose)
The sudo-and-redirect gotcha. Run the failing command so students read the error.
When students get stuck
What you will see
A question to ask
The fix
Permission denied writing smb.conf.
Are you using sudo echo with >> ?
echo ... | sudo tee -a file.
The share does not appear.
Did you restart smbd?
sudo systemctl restart smbd.
Answers to the checks
no restart: You add a [classshare] section to smb.conf but do not restart smbd. Does smbclient -L localhost list classshare? No. Services read their config when they start. After a change, restart (or reload) the service.
Try: add a share: Add a share called classshare to /etc/samba/smb.conf, restart smbd, then run smbclient -L localhost.
echo -e "[classshare]\npath = /srv/class" | sudo tee -a /etc/samba/smb.conf, then sudo systemctl restart smbd. tee, because sudo echo ... >> would still be your shell writing.
Writing to a file you do not own: Why does sudo echo "[x]" >> /etc/samba/smb.conf fail? The >> runs in your shell, not under sudo Your shell sets up the redirect before sudo runs, so it has no permission to write the file. Use echo ... | sudo tee -a file, so tee (running as root) does the writing.
Find the mistake: Sam fixes the share. Click the line where it first goes wrong. line 2 Line 2: 777 lets everyone do everything. The cause was that Alex isn't in the folder's group. Fix that: sudo chgrp class /srv/class and chmod 775.
Who can add files: /srv/class is drwxrwxr-x, owner root, group class. Who can add files? Root and members of class Owner (rwx) and group (rwx) can write; everyone else (r-x) can only read.
Group the folder: Make /srv/class belong to the group class.
sudo chgrp class /srv/class.
Let the group write: /srv/class belongs to class, but Alex still cannot save a file there. Fix the permissions.
sudo chmod 775 /srv/class: the group needs w.
Take rights away: Someone set /srv/class to 777. Bob is not in class and should only be able to read. Fix it.
sudo chmod 775 /srv/class (or o-w): others lose w.
Others: A folder is rwxrwxr-x with group class. Alex is not in class. What can Alex do? Read it, but not add files Others get r-x: look in, but not change.
After a change: You change smb.conf. What must you do for Samba to use it? Restart (or reload) smbd smbd reads its settings at start-up.
Review: enable: Review: you ran sudo systemctl enable smbd. Is smbd running now? Maybe not: enable only acts at the next boot Check with systemctl status.
a class hand-in share: Share /srv/class as [class] so that Alex (in group class) can save files there.
Add the [class] share with its path, restart smbd, set the folder's group to class and mode 775.
Solutions
One possible solution for each task. Other correct programs are fine.
Vary: change one thing › Group the folder
Open task: any program that does what the step asks.
Vary: change one thing › Let the group write
Open task: any program that does what the step asks.
Vary: change one thing › Take rights away
Open task: any program that does what the step asks.
a class hand-in share
Open task: any program that does what the step asks.
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.
Exit ticket
Why does smbd need a restart after you edit smb.conf?
It reads the file when it starts, not every time it is used.
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.
Where it leads
Links: Who can read what (permissions); Accounts, groups and sudo; next: Host Jellyfin.