element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
RoadTests & Reviews
  • Products
  • More
RoadTests & Reviews
Blog HARTING MICA: Manage Access to USB and other Devices
  • Blog
  • RoadTest Forum
  • Documents
  • RoadTests
  • Reviews
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join RoadTests & Reviews to participate - click to join for free!
  • Share
  • More
  • Cancel
  • Author Author: Jan Cumps
  • Date Created: 3 May 2019 3:41 PM Date Created
  • Views 1125 views
  • Likes 6 likes
  • Comments 3 comments
Related
Recommended
  • debian
  • iiot
  • security
  • mica
  • harting
  • device
  • stretch
  • iiot4
  • linux

HARTING MICA: Manage Access to USB and other Devices

Jan Cumps
Jan Cumps
3 May 2019

I'm road testing the Harting MICA Complete IIoT Starter Kit.

In this post, I review the mechanism to restrict or grant access to character devices such as USB and serial ports.

image

I'm showing the principle on a Linux Debian Stretch Container. The principle is true for all containers.

 

How Does the Device Assignment work?

 

In the MICA web application, there's an management page that allows to select the devices that are assigned to a particular container.

Each container has all available device available in the /dev directory. Even if they aren't selected for that container.

All devices that aren't selected are assigned to the Linux group root.

if you execute the command ls -l /dev , you'll see that all devices are there, whether they are selected in the management app or not.

Here's an example filtered on the BOSCH CISS USB device that comes with the MICA IIoT USB kit. Check the group assignment: root.

 

image

 

If you select that /dev/ttyACM0 device and assign it to your container (see the image in the post intro), and restart the MICA (not only your container!),

the ownership changes to the dialout group.

 

image

 

image

 

You can use this mechanism in the container. But that requires that you don't execute our programs as root (root has access to everything, whatever the group).

More on that in the next section.

 

Test the Setup with a non-root User

 

Let's try this out.

Steps:

  • don't list the device in the management app.
  • create a new user
  • test if the new user can access the device (should fail)
  • list the device in the management app and reboot the MICA
  • test again (should fail)
  • assign the new user to the dialout group
  • log on and test again (should work)

 

You can test by executing cat /dev/ttyACM0 , but in this example I'll use a Java program I made for this roadtest (because that's how I tested it - I don't want to redo the exercise image ).

 

I created a user jancumps

 

useradd -m jancumps
passwd jancumps

 

Moved the java libraries to the new user's home directory using winSFTP, logged in as jancumps.

It's easyest if you move them as that user, so you don't have to change any ownership and rights.

Then execute my code (if you don't have the Java program, run cat /dev/ttyACM0).

It fails - as expected, because only root group can access the device.

 

$ ls -l /dev | grep ttyA
crw-r----- 1 root root 166,   0 May  3 14:02 ttyACM0
$ java -cp ./CISSBoschUSB-1.0-SNAPSHOT.jar:./commons-cli-1.4.jar:jSerialComm-2.5.0.jar net.cumps.cissboschusb.CISSBoschApp -usb "/dev/ttyACM0" -baud 115200
May 03, 2019 2:07:38 PM net.cumps.cissboschusb.Cli parse
INFO: Using cli argument -usb=/dev/ttyACM0
May 03, 2019 2:07:38 PM net.cumps.cissboschusb.Cli parse
INFO: Using cli argument -baud=115200
May 03, 2019 2:07:39 PM net.cumps.cissboschusb.CISSNode connect
SEVERE: Open port failed
May 03, 2019 2:07:39 PM net.cumps.cissboschusb.CISSBoschApp main
INFO: Disconnecting
Exception in thread "main" java.lang.NullPointerException
        at net.cumps.cissboschusb.CISSNode.stream(CISSNode.java:56)
        at net.cumps.cissboschusb.Cli.parse(Cli.java:68)
        at net.cumps.cissboschusb.CISSBoschApp.main(CISSBoschApp.java:35)
May 03, 2019 2:07:39 PM net.cumps.cissboschusb.CISSBoschApp$1 run
INFO: Shutdown hook

 

I add /dev/ttyACM0 to the container, and reboot the whole MICA.

Log in as jancumps again and execute.

As expected, it fails, because user jancumps is not part of the dialout group:

 

$ ls -l /dev | grep ttyA
crw-rw---- 1 root dialout 166,   0 May  3 14:05 ttyACM0
$ pwd
/home/jancumps/java
$ java -cp ./CISSBoschUSB-1.0-SNAPSHOT.jar:./commons-cli-1.4.jar:jSerialComm-2.5.0.jar net.cumps.cissboschusb.CISSBoschApp -usb "/dev/ttyACM0" -baud 115200
May 03, 2019 2:07:38 PM net.cumps.cissboschusb.Cli parse
INFO: Using cli argument -usb=/dev/ttyACM0
May 03, 2019 2:07:38 PM net.cumps.cissboschusb.Cli parse
INFO: Using cli argument -baud=115200
May 03, 2019 2:07:39 PM net.cumps.cissboschusb.CISSNode connect
SEVERE: Open port failed
May 03, 2019 2:07:39 PM net.cumps.cissboschusb.CISSBoschApp main
INFO: Disconnecting
Exception in thread "main" java.lang.NullPointerException
        at net.cumps.cissboschusb.CISSNode.stream(CISSNode.java:56)
        at net.cumps.cissboschusb.Cli.parse(Cli.java:68)
        at net.cumps.cissboschusb.CISSBoschApp.main(CISSBoschApp.java:35)
May 03, 2019 2:07:39 PM net.cumps.cissboschusb.CISSBoschApp$1 run
INFO: Shutdown hook

 

As root, then add the dialout group to user jancumps.

 

usermod -aG dialout jancumps

 

Log out and log in as jancumps again (group changes need a fresh logon to apply), and it succeeds:

 

$ ls -l /dev | grep ttyA
crw-rw---- 1 root dialout 166,   0 May  3 14:05 ttyACM0
$ cd java
$ java -cp ./CISSBoschUSB-1.0-SNAPSHOT.jar:./commons-cli-1.4.jar:jSerialComm-2.5.0.jar net.cumps.cissboschusb.CISSBoschApp -usb "/dev/ttyACM0" -baud 115200
May 03, 2019 2:08:08 PM net.cumps.cissboschusb.Cli parse
INFO: Using cli argument -usb=/dev/ttyACM0
May 03, 2019 2:08:09 PM net.cumps.cissboschusb.Cli parse
INFO: Using cli argument -baud=115200
May 03, 2019 2:08:10 PM net.cumps.cissboschusb.CISSNode connect
INFO: Open port succeeeded

 

Summary: the device selection changes the group ownership of selected devices.

Non-selected devices can only be accessed by users belonging to the root group.

Selected devices can be accessed by users belonging to the dialout group - a group that you can safely assign to users without needing root level elevation.

This functionality is useful but requires that you properly set up users and groups in your container.

 

Related Blog
HARTING MICA: Develop and Debug a C GPIO Example in Eclipse - Part 1: User Experience
HARTING MICA: Develop and Debug a C GPIO Example in Eclipse - Part 2: MICA Debian Stretch Setup
HARTING MICA: Develop and Debug a C GPIO Example in Eclipse - Part 3: Eclipse Configuration on Windows
HARTING MICA: Develop and Debug a C GPIO Example in Eclipse - Part 4: Build and Debug the GPIO Example
HARTING MICA: Make a Safe(r) MQTT Container with Certificate and TLS/SSL
HARTING MICA: Manage Access to USB and other Devices
HARTING MICA: SD Card as Shared Storage
HARTING MICA: Alpine Linux and another MQTT Container with Certificate and TLS/SSL
HARTING MICA: Connect to Amazon Web Services
HARTING MICA: Install Java 8 VM in a Debian Stretch Container
HARTING MICA: Read BOSCH CISS Sensor with Java - part 1: USB Connect and Listen
  • Sign in to reply

Top Comments

  • stevesmythe
    stevesmythe over 6 years ago +1
    How Does the Device Assignment work? In the MICA web application, there's an management page that allows to select the devices that are assigned to a particular container. Each container has all available…
  • Jan Cumps
    Jan Cumps over 6 years ago in reply to stevesmythe

    fixed

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • stevesmythe
    stevesmythe over 6 years ago
    How Does the Device Assignment work?

     

    In the MICA web application, there's an management page that allows to select the devices that are assigned to a particular container.

    Each container has all available device available in the /dev directory. Even if they aren't selected for that container.

    All devices that aren't selected are assigned to the Linux group root.

    if you execute the command ld -l /dev , you'll see that all devices are there, whether they are selected in the management app or not.

    Very small typo - should say "ls -l /dev" (as per your screenshot later).

     

    This is another useful blog post, as this process does not seem to be explained anywhere in the HARTING documentation.

     

    Steve

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • DAB
    DAB over 6 years ago

    Nice update Jan.

     

    DAB

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube