john plugs in a USB drive labeled FlashDrive, it appears at:
Allowing Non-Root Mounts via /etc/fstab
You can configure/etc/fstab to let normal users mount and unmount specific devices without sudo. Modify the mount options field to include one of the following:
| Option | Description | Default |
|---|---|---|
| user | Allow any user to mount and unmount | (no) |
| nouser | Disallow non-root mounts | yes |
| group | Allow users belonging to the owning group | (no) |
| owner | Allow the device’s owning user | (no) |
/dev/sdb1 on /mnt/userdrive:
After editing
/etc/fstab, you can test the entry without rebooting:Managing Mounts with systemd
systemd can manage both static mounts and on-demand automounts via unit files in/etc/systemd/system/. Units must be named after the mount point by replacing slashes with hyphens and appending .mount or .automount.
Creating a Mount Unit
-
Create the file
/etc/systemd/system/mnt-external.mount: -
Populate it:
| Field | Purpose |
|---|---|
| Description | Brief description of the mount |
| What | Device path or UUID (/dev/disk/by-uuid/...) |
| Where | Mount point directory (/mnt/external) |
| Type | Filesystem type (ntfs, ext4, etc.) |
| Options | Mount options (same as in /etc/fstab) |
| WantedBy | Target to activate the mount on (multi-user.target) |
The filename
mnt-external.mount must exactly match the Where path /mnt/external (slashes → hyphens).-
Reload systemd and start the mount:
-
Check status:
Sample output:
-
To auto-mount at boot:
Creating an Automount Unit
An automount unit triggers the mount only when the directory is accessed. You’ll need both the.mount and a corresponding .automount file.
-
Create
/etc/systemd/system/mnt-external.automount: -
Add:
-
Reload, start, and enable:
ls /mnt/external, systemd will mount the disk automatically.