Run usermod definition

Dear Support,

In order to use GPIO in VS code, needs to add the torizon user to the gpio group.
Groups are mirrored between the base OS and the Debian containers for Torizon. Edit the buildcommands property and set it to [RUN usermod -a -G gpio torizon]

if I want to use SPI in VS code needs to [RUN usermod -a -G spidev torizon]: It is required to allow the users in this group to access SPI devices without root privileges.

In VS code, what should I write if I want to use SPI and GPIO together in the BuildCommands? Both of them with a [&] symbol?

What do -a and -G stand for?

Best regards,
Mehrdad

Hi @Mehrdad ,

In VS code, what should I write if I want to use SPI and GPIO together in the BuildCommands? Both of them with a [&] symbol?

I don’t think you can add two commands in a single property like

RUN usermod -a -G gpio torizon && usermod -a -G spidev torizon

or something similar.

Fortunately, while it is true that the user needs to be in the gpio and spidev groups in order to access GPIO and SPI respectively, I believe the latest versions of our Debian containers already adds user torizon to these groups by default.

Therefore, you shouldn’t need to add anything in the buildcommands property. GPIO and SPI should work once everything else is set up correctly. I’ll ask internally to update the text in our articles to reflect this, thanks for pointing that out!

What do -a and -G stand for?

These are options for the usermod command. See the manual page for more details: man usermod (8): modify a user account. A simpler explanation of the command can be found here: https://linuxize.com/post/usermod-command-in-linux/#add-a-user-to-a-group.

Best regards,
Lucas Akira

1 Like

Hi @lucas_a.tx ,
Thank you so much for your help. You made my day!

I am working on SPI to connect DAC7760 evaluation board to the verdin board imx8 mini with VS code, and in the example, for SPI

in section 2 [ Paste the source code into the main c file.] I have to add spidev_test.c just? or spidev_fdx.c as well? and should I change the makefile?

Thank you so much in advance.
Best regards,
Mehrdad

Hi @Mehrdad ,

Glad I was able to help!

For the SPI example section of the article, only spidev_test.c is necessary. You don’t need to change the Makefile, the default one generated from the project template should work.

Best regards,
Lucas Akira

Just a quick note about usermod: If you need to add a user to multiple groups, you can do so with a single usermod command, like:

RUN usermod -a -G group1,group2 torizon

in buildcommands.

Again, this shouldn’t be needed for SPI and GPIO access, but it’s good to know if for any other reason you need to add a user to multiple groups at once.

Best regards,
Lucas Akira

1 Like