Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ntfs-3g-mount: mount failed: Operation not permitted #2

Open
UnCanard14 opened this issue Mar 7, 2024 · 6 comments
Open

ntfs-3g-mount: mount failed: Operation not permitted #2

UnCanard14 opened this issue Mar 7, 2024 · 6 comments

Comments

@UnCanard14
Copy link

Hi I have this issue when the usb key launch the script :

ntfs-3g-mount: mount failed: Operation not permitted
User doesn't have privilege to mount. For more information
please see: http://tuxera.com/community/ntfs-3g-faq/#unprivileged
umount: /tmp/sdd: must be superuser to unmount.
Copy to sdd >> Done !
sudo: unknown user stf
sudo: error initializing audit plugin sudoers_audit

@stonfute
Copy link
Owner

stonfute commented Mar 7, 2024

sudo: unknown user stf

Please read the Readme

@UnCanard14
Copy link
Author

I am using ubuntu 23.10

ntfs-3g-mount: mount failed: Operation not permitted
User doesn't have privilege to mount. For more information
please see: http://tuxera.com/community/ntfs-3g-faq/#unprivileged
umount: /tmp/sdb: must be superuser to unmount.
Copy to sdb  >> Done !

And I see here it is impossible to mount device :

Note that running programs that access the network or mount/unmount filesystems is not allowed inside of udev rules, due to the default sandbox that is enforced on systemd-udevd.service.

@stonfute
Copy link
Owner

stonfute commented Mar 8, 2024

seems weird ... maybe new restrictions in new released.
Don't have such setup right now to reproduce.

Found some similar issues here : https://unix.stackexchange.com/a/759022

Maybe one workaround is to use screen to launch usbhook.sh ?
Change the rule to :
ACTION=="add",KERNEL=="sd*", SUBSYSTEMS=="usb", ATTRS{product}=="*", RUN+="/usr/bin/screen /home/stf/usbhook.sh %k"

@UnCanard14
Copy link
Author

Not working for me, I will try with systemd 😄

@stonfute
Copy link
Owner

stonfute commented Mar 8, 2024

let me know !

@UnCanard14
Copy link
Author

You'll need to modify the script a little to match yours, but I've done the following:

Usb update

Doc to update a file when a USB flash drive is plug.

  1. Add a script :

nano /home/user/usbhook.sh

#!/usr/bin/env bash
# Debugging test script called by udev

# File paths, to be customized as needed
logFile="/tmp/logFileUsbHook.txt"
dateFile="/tmp/.logDateUsbHook.date"

# Ensure only one instance is running at a time
instances=$(lsof -t "$0" | wc -l)
if (( $instances > 1 )); then exit 1; fi

# Prevent multiple executions inside a 3-second time frame
if [ ! -f $dateFile ]; then
    echo "lastExecution=0" > $dateFile
fi
source $dateFile # reads the $lastExecution var from file
timeframe=$(( $(date +%s) - $lastExecution )) # seconds from last execution
if (( $timeframe <= 3 )); then exit 1; fi
echo "lastExecution=$(date +%s)" > $dateFile

# Debugging info
echo "USB Device '$1' plugged in..." >> $logFile

sleep 5

# Retrieve the mount point of the USB device based on the device name
device_name="$1"
usb_mount_point=$(grep "$device_name" /etc/mtab | awk '{print $2}')

# Check if the USB device is mounted
if [ -n "$usb_mount_point" ]; then
    # Access the directory of the USB device
    cd "$usb_mount_point"
    echo "USB device directory: $usb_mount_point" >> $logFile

    # Check for the presence of the update.zip file
    if [ -e "update.zip" ]; then
        echo "The update.zip file was found." >> $logFile
        
        # Unzip the update.zip file into the temporary directory
        unzip -d /tmp/ "update.zip" >> $logFile 2>&1

        # Do other stuff with the content of update.zip...
        
        echo "The update.zip file was unzipped into /tmp/." >> $logFile
    else
        echo "The update.zip file was not found." >> $logFile
    fi
else
    echo "No mount point found for the device $device_name." >> $logFile
fi

# Do other stuff...
exit 0

Dont't forget to add execution with :
chmod +x /home/user/usbhook.sh

  1. Add an udev rule to trigger usb key connection :

sudo nano /etc/udev/rules.d/99-usbhook.rules

ACTION=="add", KERNEL=="sd*", SUBSYSTEMS=="usb", TAG+="systemd", ENV{SYSTEMD_WANTS}="dummy@%k.service"

Reload rules

sudo udevadm control --reload-rules

  1. Add service :

sudo nano /etc/systemd/system/[email protected]

[Unit]
Description=Run script on USB plug

[Service]
Type=oneshot
ExecStart=/home/simon/usbhook.sh %i
RemainAfterExit=no

Reload services

systemctl daemon-reload

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants