Skip to content

About

Plug-and-play USB storage automount and Samba network file sharing auto-configuration script for Linux servers.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

USB Share Setup

Plug a USB drive in and it is mounted automatically under /media/usb-share/<label>, then shared on the LAN via a guest-visible Samba share. A udev rule triggers a systemd template service on every hotplug event; the mount/unmount logic lives in a short bash script.

What's included

File Purpose
99-usb-mount.rules udev rule: fires usb-mount@ for any USB block device with a filesystem
usb-mount@.service systemd oneshot: calls the mount script
usb-mount.sh Bash: mounts on add, unmounts & cleans up on remove
samba_snippet.conf Samba [USB-Share] block to paste into smb.conf

Installation

# Install files to the right locations
sudo cp usb-mount.sh /usr/local/bin/usb-mount.sh
sudo chmod +x /usr/local/bin/usb-mount.sh

sudo cp 99-usb-mount.rules /etc/udev/rules.d/
sudo cp usb-mount@.service  /etc/systemd/system/
sudo udevadm control --reload-rules

# Merge the Samba share into your smb.conf
# (edit path / force user to match your system)
cat samba_snippet.conf >> /etc/samba/smb.conf
sudo systemctl restart smbd

How it works

  1. A USB drive with a recognised filesystem appears → udev fires usb-mount@<dev>.service.
  2. usb-mount.sh add <dev> creates /media/usb-share/<label>, picks the right mount options (FAT/NTFS/exFAT get explicit uid/gid/umask for Samba compatibility), and mounts it.
  3. On removal the script unmounts, deletes empty subdirectories, and cleans up.
  4. Samba makes the root of /media/usb-share readable (and writable) to guest users.

Security notes

The included Samba snippet uses guest ok = yes for easy LAN sharing — tighten this for public or remote-facing servers. The mount options nosuid,nodev,noatime are applied to all filesystems to prevent privilege-escalation via SUID binaries on the drive.

Repository details

  • Short description: Zero-touch USB auto-mount + Samba LAN share for Linux servers.
  • Suggested topics: samba, usb, udev, systemd, linux, network-share, homelab, automation
  • License recommendation: MIT.

About

Plug-and-play USB storage automount and Samba network file sharing auto-configuration script for Linux servers.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages