Sub topic 1
How network file sharing works
Prerequisites
You should be comfortable with the Linux command line and a text editor. You should know Linux users, groups, and file permissions (chmod, chown), basic TCP/IP concepts such as IP addresses and subnets, and how to install packages and manage services with systemctl.
Network file sharing
A file server keeps files on its disk and lets other machines read and write them over the network. A client sends a request, the server checks who is asking, and then the server reads or writes the file locally. On Linux, two protocols do this work. SMB (Server Message Block, also called CIFS) is common in mixed Windows networks. NFS (Network File System) is the native choice between Unix-like systems.
SMB and the Samba daemons
Samba is the open-source implementation of SMB for Linux. Its main daemon, smbd, serves file shares and enforces access. The nmbd daemon answers NetBIOS name requests on older networks. The service unit is named smbd on Debian and Ubuntu and smb on Red Hat-family systems.
Anatomy of smb.conf
The main configuration file is /etc/samba/smb.conf. It has a [global] section for server-wide settings and one section per share.
[global]
workgroup = WORKGROUP
server role = standalone server
map to guest = never
[projects]
path = /srv/samba/projects
read only = no
valid users = @staffRun testparm -s after every edit. It checks the syntax and prints the effective configuration.
Creating Samba users
Samba keeps its own password database. Each Samba user must first exist as a Linux account, because Samba maps the login to a local user.
sudo groupadd staff
sudo useradd -M -s /usr/sbin/nologin -G staff alice
sudo smbpasswd -a aliceThe -M flag skips home directory creation, and /usr/sbin/nologin blocks shell logins. smbpasswd -a prompts for a Samba password, which is separate from the Linux password.
Defining shares and permissions
Two layers control access. The share settings in smb.conf decide who may connect. File permissions decide what connected users can do.
sudo mkdir -p /srv/samba/projects
sudo chgrp staff /srv/samba/projects
sudo chmod 2775 /srv/samba/projectsThe setgid bit (the leading 2) makes new files inherit the staff group. With create mask = 0664 in the share, new files also get group write permission.
> Not valid here: this line is a placeholder.
Exercise
Why does smbpasswd -a bob fail when no Linux account named bob exists?
Show answer
Samba maps each login to a local Linux user, so the Linux account must exist before you add the Samba password.