Table of Contents
Note
26/2/2023: Trash folder added.
28/7/2022: Correct the positions of two statements. "gedit" changed to "nano" in case non gui interface is used.
7/5/2019: Slight adjustments. "gksudo gedit" changed to "sudo gedit" as Ubuntu 18.04 dropped "gksudo".
25/12/2014: First created.
-> TopIntro
Samba file server enables specified directories to be accessible by Windows computers on the same network.
-> TopInstall
Install the packages:
$ sudo apt update $ sudo apt install samba $ sudo apt install samba-vfs-modules
samba-vfs-modules is used to enable Trash folder.
(vsf-modules added, 26/2/2023)
-> TopDefine a workgroup
Edit the config file:
$ sudo nano /etc/samba/smb.conf
Define workgroup name as "kctcl" in the "[global]" section:
workgroup = kctcl
Uncomment to restrict access to server users only:
security = user
Add the following if OpenVPN used:
hosts allow = 192.168.0. 10.8.0. 127.0.0.
(added. 7/5/2019):
Put the last two statements under the "[global]" section after "Networking" instead of at the end, otherwise "security = user" will apply to the last shared directory causing it to be non-assessible.
(added, 28/7/2022)
-> TopDefine directories to be shared
Add a section at the end to share directories:
[<sub-directory name or other short name>] pth = /<directory name>/<sub-directory name> browseable = yes guest ok = yes read only = no create mask = 0775 directory mask = 0775 # do not include the next two lines if access is restricted to the owning user (added 7 May 2019) force user = nobody force group = nogroup # Enable Trash folder, KCTang 18/1/2023 vfs object = recycle # Specify a folder relative to the path above # Do not specify absolute path unless the path is outside the path above # The folder will be created automatically upon first deletion # Hidden folder (prefixed with '.') not used # Use %U if want to record the user name, not used KCTang 26/2/2023 #recycle:repository = Trash/%U recycle:repository = Trash # Mode permits all users to delete recycle:directory_mode = 0775 # Change last accessed time when moved to the Trash folder recycle:touch = yes # Keep modified time recycle:touch_mtime = no # Keep folder tree recycle:keeptree = yes # Files of the same name deleted will be kept with newer deleted file named as "Copy # of ..." recycle:versions = yes # Exclusions recycle.exclude = *.tmp, ~*, thumb.db
(Trash folder added, 26/2/2023)
Create the directory to be shared, if not already existing:
$ sudo mkdir -p /<directory name>/<sub-directory name>
Change ownership of the directory:
$ sudo chown nobody:nogroup /<directory name>/<sub-directory name>-> Top
Start service
Start or restart Samba service whenever the config file is changed:
$ sudo systemctl restart smbd nmbd
or, if ".service" is not automatically appended when executing the above command:
$ sudo systemctl restart smbd.service nmbd.service-> Top
Define Crontab
Define crontab to delete Samba Trash files older than 30 days:
$ crontab -e
Edit to include:
#Delete Samba Trash files folder than 30 days 0 0 * * * /usr/bin/find /kctcl/Trash -type f -atime +30 -delete
(added, 26/2/2023)
-> Top