1

My current Situation:

  • my pc is running Xubuntu 16.04
  • a java jar app on Xubunutu desktop
  • a USB thermal printer (Model: DigiPOS 920) is connected via USB to my pc
  • the java app talks to the thermal printer via Java-POS and not via CUPS

My Question:

I am able to print but only if I have started my app via the terminal as su. If I just double click the jar file, I can start the app but it won't find the printer, thus no printing. Guys 'n Girls, please gimme a hint about:

How can I start the java jar App without the need for sudo? Or is there even a better approach for this case?

Chiggiddi
  • 345

2 Answers2

0

You have 4 options from least secure to most secure:

  1. Run java as root by:

    a. Marking java as setuid root. OR

    b. Using sudo to say that the app can be run as root without a password. See NOPASSWD option in /etc/sudoers; or

  2. Give all users access to the USB device mentioned:

    a. By marking the device as read-write by everyone; or

    b. By marking the device as setuid root.

It depends how the app is accessing the device as to which option will work. I recommend trying option 2a first and working your way up the list.

Note that when marking anything as setuid root, you have to find the actual binary /usr/lib/java-....-/bin/java. setuid-root-ing the "alternatives" symlink is not going to work.

0
  1. Add your user to dialout group as this group has permission to read/write serial devices tty* or serial*.

    sudo usermod -a -G dialout $USER
    

    Reference: How do i allow non-root access to /ttyUSB0 on 12.04?

    If it has parallel port interface lp* (as the current case with DigiPOS 920) add your user to lp group.

    sudo usermod -a -G lp $USER
    
  2. Logout/Login


Further instructions: If it didn't work continue with the steps below

  1. Run watch lsusb, plug & unplug the printer, edit the question and add the printer info line as it shown in the output.

  2. Run

    watch "find /dev/ -iregex '.*lp.*' -printf '%p '; find /dev/ -iregex '.*tty.*' -printf '%p '"
    

    Plug & unplug the printer, edit the question and add the device node that created when you plug printer.

  3. Add output of:

    ls -l /dev/...
    udevadm info /dev/...
    udevadm info -a /dev/...
    
  4. Quick test, change permission

    sudo chmod +rw /dev/tty...
    

    Try your program without sudo, does it work?

  5. Now, we should add a udev rule to make that permanent.

user.dz
  • 49,176