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?

  • Have you tried java -jar – mchid May 28 '16 at 0:38
  • Could you edit question an add model of your printer and how it is connected physically? I expect it is an RS-232 connection and all you need is to add your user to dialout group like in this answer or more twisted way using a udev rule. – user.dz May 30 '16 at 18:47
  • 1
    @Sneetsher Hi there, thanks for your concern and help. The Thermal Printer is connected to the PC via USB Connection. Its driver comes in as a bunch of jar-files (JavaPOS driver) which need to be moved into the jdk/bin/etc folder – Chiggiddi Jun 1 '16 at 21:28
  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.

  • 1
    I tried first to add my user to the dialout group, but this didn't work. So I checked with ls -l /dev/usb/lp0 and I got the output crw-rw---T 1 root lp ... /dev/usb/lp0; consequently my device belongs to group lp. Therefore I added my user to the lp group and did a reboot. After that printings works like a charm! Your idea and suggestion is the least complex and easiest to implement. I really need to buy you a beer! Cheers, Mate! – Chiggiddi Jun 16 '16 at 0:17
  • @Chiggiddi, Happy to hear that . Thank you for feedback, so it has a parallel interface port instead of serial . Let me update the answer. It may help others. – user.dz Jun 16 '16 at 0:32
  • Hi there, I must admit; you really exceptionally contribute to this community. Until now I haven't found any person like you that took that much dedication to help users in need. Many kudos to you! Btw, do you also offer professional (paid) assistance in Ubuntu matters? – Chiggiddi Jun 16 '16 at 9:47
  • :) @Chiggiddi thanks for the words, I never thought about that. My current work is not related and I just following as hobby for fun and learning more about free software development. – user.dz Jun 16 '16 at 10:13

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.

  • Hi tudor! Sorry for my belated reply. Btw, I love the tudor tv show! Wow, so many options to pick from. Your suggestions seem very promising, especially option 1a/b. I will take a deeper look into the NOPASSWD option. Furthermore I would like to hear your opinion about whether to give root access to Java or to the USB Device will be the more secure option? Thanks a ton! – Chiggiddi Jun 1 '16 at 21:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.