A while ago I got an udev script to run when an usb-stick is inserted into Ubuntu 16.04 (server) machine. (I've been using that to mount stick to virtualbox guest.)
Now I want to do something different in that script (mount it in the host). I've got an udev rule:
#/etc/udev/rules.d/10-usbmount.rules
KERNEL=="sd*[!0-9]|sr*", ENV{ID_SERIAL}!="?*", SUBSYSTEMS=="usb", RUN+="/bin/su <username> -c /home/<username>/automount"
It calls the automount
script which is currently:
LOG_FILE=/home/<username>/usb_log
echo "New usb device detected at $DEVNAM doing stuff
mount $DEVNAME /home/<username>/flashes_folder &>> $LOG_FILE
#mount /dev/sdb1 /home/<username>/flashes_folder &>> $LOG_FILE
ret=$?
echo "$ret" >> $LOG_FILE
(taken from here) The log file contains the following output:
New usb device detected at /dev/sdb doing stuff
mount: only root can do that
1
Explicitly entering the disk path /dev/sdb1
(commented line) does result in the same error (the disk indeed is /dev/sdb1).
Apparently, /bin/su <admin_username>
has not enough privileges. How do I fix that?