Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

How to permanently allow access to removable device

  • 16-12-2010 9:23am
    #1
    Registered Users, Registered Users 2 Posts: 19,050 ✭✭✭✭


    Hi all,
    Quick question..(hopefully)
    I have a model railway controller box which uses an FTDI FT232RL USB<->RS232 converter chip. It all works beautifully, Linux recognises the chip (I had to burn in parameters into its EEPROM etc. as it was built from parts) and I can access the device better than under windows...BUT I have a (simple?) problem:

    I have to do a $chmod 777 /dev/ttyUSB0 every time I boot up/plug the thing in or else only root can access it. Can I make this change permanent? (I need to allow Apache to have access to the device because I use a PHP script to open it and write to it/read from it but don't mind just allowing everything to have access as no harm can be done really, to make the trains move like!).

    Cheers!


Comments

  • Registered Users, Registered Users 2 Posts: 2,370 ✭✭✭Knasher


    I'd imagine that you need to write your own udev rules. Take a look at :
    http://ubuntuforums.org/showthread.php?t=168221
    http://reactivated.net/writing_udev_rules.html#ownership

    Should cover it better than I can.


  • Registered Users, Registered Users 2 Posts: 19,050 ✭✭✭✭murphaph


    Excellent knasher, I've been googling like a lunatic and neither of those showed up, shows how crap my googling skills are! I'll give that a shot this evening. Would make it much handier if I could make this a permanent change for a couple of reasons.


  • Moderators, Recreation & Hobbies Moderators, Science, Health & Environment Moderators, Technology & Internet Moderators Posts: 93,599 Mod ✭✭✭✭Capt'n Midnight


    One problem is that the usb device may not get the exact same device name
    in which case use this rule to give it a symlink to a named device

    so instead of talking to /dev/ttyUSB0 or /dev/ttyUSB1 every second resume you can just talk to /dev/gps-usb ( or rename it to /dev/ttyTrain )

    lsusb will give you the ID you need to ID your 232 device put yours in in place of
    SUBSYSTEM=="tty", SYSFS{idVendor}=="10c4", SYSFS{idProduct}=="ea60", SYMLINK="gps-usb"

    http://www.fridu.org/images/opencpn/70-persistent-usb-gps.rules
    # 
    # Author: Fulup Ar Foll
    # Date:   26-jun-09
    # Object: make sure GPS dev (ex: /dev/gps-usb) dont change name on sleep/wakeup
    # -----------------------------------------------------------------------------
    #
    # 1) place this file in /etc/udev/rules.d
    # 2) use default config or update with your own vendor:product ID (use "lsusb" to find them)
    # 3) reload udev with "/etc/init.d/udev reload"
    #
    # Device alias can be:
    #  (default) - by path  ==> SYMLINK="serial-$env(ID_PATH)"   /dev/gps-pci-0000:00:1d.1-usb-0:1:1.0
    #            - static   ==> SYMLINK="gps-usb"                /dev/gps-usb
    #            - custom   ==> RUN+="/usr/local/bin/myscript"   /dev/any-thingk-you-want
    #
    # DEFAULT CONFIG: you can use this file "as it is", you should then see a /dev/gps-pci* 
    # that will be created for any of the serial/usb you hot-plug. The name is fixe but
    # depend on the USB port you use. As a result the name is fix until you keep the same socket.
    #
    # -----------------------------------------------------------------------
    # check "man 7 udev" for forther syntax. (search for %n)
    # -----------------------------------------------------------------------
    
    # Examples
    # -----------------------------------------------------------------------
    # Your own script:     SUBSYSTEM=="tty", SYSFS{idVendor}=="xxxx", SYSFS{idProduct}=="yyyy", RUN+="/usr/local/bin/myscript"
    # Static device name:  SUBSYSTEM=="tty", SYSFS{idVendor}=="xxxx", SYSFS{idProduct}=="yyyy", SYMLINK="gps-usb"
    # Path dependent name: SUBSYSTEM=="tty", SYSFS{idVendor}=="xxxx", SYSFS{idProduct}=="yyyy", SYMLINK="gps-$env{ID_PATH}"
    # In first case you do what ever you want, script receive the information about context in environement variables
    # In second case you name is fixe (ex: /dev/gps-usb) this is working if your usb/serial ID(vendor:product) is unique
    # In third case your device name depend on the port it is plugged in.
    
    
    # ========================================================================================
    #                          update YOUR CONFIG here after
    # ========================================================================================
    
    # Default rules is applied for any unspecified vendor:product devices
    # -----------------------------------------------------------------------------------------
    SUBSYSTEM=="tty", SYSFS{idVendor}=="?*", SYSFS{idProduct}=="?*", SYMLINK="gps-$env{ID_PATH}"
    
    # Well known device may get a static device name 
    # -----------------------------------------------------------------------
    SUBSYSTEM=="tty", SYSFS{idVendor}=="10c4", SYSFS{idProduct}=="ea60", SYMLINK="gps-usb"
    


  • Registered Users, Registered Users 2 Posts: 19,050 ✭✭✭✭murphaph


    Thanks again guys, implemented new rule with symlink, dependent on chip serial number (had burned this in myself previously) in udev and it reliably now mounts automatically with the symlink being created in /dev and my app has permanent access to it (using mode="0666"). I tried to add just group="www-data" (because my app is PHP running under Apache. I haven't changed the defaults and checked apache2.conf and apache is indeed group: "www-data" so not sure why it doesn't work doing it this way. It works the other way though and I'm happy enough tbh as that's all I wanted to get working initially. Thanks again for the tips.


Advertisement