Actions

EmSys

Difference between revisions of "Accessing Devices without Sudo"

From EdWiki

m (Step 1: Add the User to the plugdev Group)
m
Line 1: Line 1:
On Linux, [[EmSys:OpenOCD |OpenOCD]] requires superuser privileges to communicate with your USB drivers. You can give [[EmSys:OpenOCD |OpenOCD]] superuser priveleges with the ''sudo'' command, like this:
+
On Linux, [[EmSys:OpenOCD |OpenOCD]] requires superuser privileges to communicate with your USB drivers. You can give [[EmSys:OpenOCD |OpenOCD]] superuser priveleges with the ''sudo'' command, like this:<br /><br />
  
  sudo openocd [-f ...]
+
  sudo openocd [-f ...]<br /><br />
  
 
...but ''sudo'' prompts the user for the root password. Suppose you want to allow a user to run [[EmSys:OpenOCD |OpenOCD]] without a root password, or you just don't want to type ''sudo'' each time you run [[EmSys:OpenOCD |OpenOCD]]. This guide will demonstrate how to configure Ubuntu Linux to allow a particular user to run [[EmSys:OpenOCD |OpenOCD]] for a device without ''sudo''.
 
...but ''sudo'' prompts the user for the root password. Suppose you want to allow a user to run [[EmSys:OpenOCD |OpenOCD]] without a root password, or you just don't want to type ''sudo'' each time you run [[EmSys:OpenOCD |OpenOCD]]. This guide will demonstrate how to configure Ubuntu Linux to allow a particular user to run [[EmSys:OpenOCD |OpenOCD]] for a device without ''sudo''.
Line 7: Line 7:
 
===Step 1: Add the User to the ''plugdev'' Group===
 
===Step 1: Add the User to the ''plugdev'' Group===
  
Determine if the user is part of the ''plugdev'' group with the ''groups'' command. Open a terminal window and type:
+
Determine if the user is part of the ''plugdev'' group with the ''groups'' command. Open a terminal window and type:<br /><br />
  
  groups USERNAME
+
  groups USERNAME<br /><br />
  
...replacing USERNAME with the name of the user account. The ''groups'' command will print a list of all of the user's groups. Look for the group ''plugdev''. If the user is not already a member of ''plugdev'', add the user with the ''adduser'' command:
+
...replacing USERNAME with the name of the user account. The ''groups'' command will print a list of all of the user's groups. Look for the group ''plugdev''. If the user is not already a member of ''plugdev'', add the user with the ''adduser'' command:<br /><br />
  
  sudo adduser USERNAME plugdev
+
  sudo adduser USERNAME plugdev<br /><br />
  
 
Run ''groups USERNAME'' again to verify that the user is now part of ''plugdev''.
 
Run ''groups USERNAME'' again to verify that the user is now part of ''plugdev''.
Line 19: Line 19:
 
===Step 2: Determine your Device's Vendor ID and Product ID===
 
===Step 2: Determine your Device's Vendor ID and Product ID===
  
The vendor ID and product ID for the [[EmSys:Tiva C Series TM4C123GXL Board | EK-TM4C123GXL Board]] adapter are as follows:
+
The vendor ID and product ID for the [[EmSys:Tiva C Series TM4C123GXL Board | EK-TM4C123GXL Board]] adapter are as follows:<br /><br />
  
 
  idVendor = "1cbe
 
  idVendor = "1cbe
  idProduct = 00fd
+
  idProduct = 00fd<br /><br />
  
 
For any other device, plug it in, then use the [[EmSys:Lsusb (Linux)|''lsusb'' command]] to retrieve your hardware's vendor ID and product ID. You will need them below.
 
For any other device, plug it in, then use the [[EmSys:Lsusb (Linux)|''lsusb'' command]] to retrieve your hardware's vendor ID and product ID. You will need them below.
Line 28: Line 28:
 
===Step 3: Add the Device to udev===
 
===Step 3: Add the Device to udev===
  
Now you need to add your hardware to the ''plugdev'' group. In the terminal window, navigate to '''/etc/udev/rules.d''' and list the contents of the directory.
+
Now you need to add your hardware to the ''plugdev'' group. In the terminal window, navigate to '''/etc/udev/rules.d''' and list the contents of the directory.<br /><br />
  
 
  cd /etc/udev/rules.d
 
  cd /etc/udev/rules.d
  ls
+
  ls<br /><br />
  
 
In a fresh installation of Ubuntu 10.04 you should see two files listed: '''70-persistent-cd.rules''' and '''70-persistent-net.rules'''. If you see other files, proceed with caution. If in doubt contact your system administrator. If you are ready to proceed, create a new file in the '''gedit''' text editor.
 
In a fresh installation of Ubuntu 10.04 you should see two files listed: '''70-persistent-cd.rules''' and '''70-persistent-net.rules'''. If you see other files, proceed with caution. If in doubt contact your system administrator. If you are ready to proceed, create a new file in the '''gedit''' text editor.
Line 39: Line 39:
 
You can name this file whatever you want, so long as it ends in ".rules". However, rules files by convention begin with a number. Linux parses rules files in lexical order, and the number makes it easy to see which files will be parsed first. Choosing a low number (like 10, as above) means that your file will be parsed before system rules files.  
 
You can name this file whatever you want, so long as it ends in ".rules". However, rules files by convention begin with a number. Linux parses rules files in lexical order, and the number makes it easy to see which files will be parsed first. Choosing a low number (like 10, as above) means that your file will be parsed before system rules files.  
  
Add the following text to the file, replacing VENDOR_ID and PRODUCT_ID with the values you found in Step 2 above.
+
Add the following text to the file, replacing VENDOR_ID and PRODUCT_ID with the values you found in Step 2 above.<br /><br />
  
  ATTRS{idProduct}=="[PRODUCT_ID]", ATTRS{idVendor}=="[VENDOR_ID]", MODE="666", GROUP="plugdev"
+
  ATTRS{idProduct}=="[PRODUCT_ID]", ATTRS{idVendor}=="[VENDOR_ID]", MODE="666", GROUP="plugdev"<br /><br />
 
   
 
   
For the[[EmSys:Tiva C Series TM4C123GXL Board | EK-TM4C123GXL Board]], the text should look like this:
+
For the[[EmSys:Tiva C Series TM4C123GXL Board | EK-TM4C123GXL Board]], the text should look like this:<br /><br />
  
  ATTRS{idProduct}=="00fd", ATTRS{idVendor}=="1cbe", MODE="666", GROUP="plugdev"
+
  ATTRS{idProduct}=="00fd", ATTRS{idVendor}=="1cbe", MODE="666", GROUP="plugdev"<br /><br />
  
On older Ubuntu installations you may need to use ''SYSFS'' instead of ''ATTRS'', like this:
+
On older Ubuntu installations you may need to use ''SYSFS'' instead of ''ATTRS'', like this:<br /><br />
  
  SYSFS{idProduct}=="00fd", SYSFS{idVendor}=="1cbe", MODE="666", GROUP="plugdev"
+
  SYSFS{idProduct}=="00fd", SYSFS{idVendor}=="1cbe", MODE="666", GROUP="plugdev"<br /><br />
  
Save the file and close it. Now tell Ubuntu to reload udev rules by entering the following in the terminal window:
+
Save the file and close it. Now tell Ubuntu to reload udev rules by entering the following in the terminal window:<br /><br />
  
  sudo udevadm trigger
+
  sudo udevadm trigger<br /><br />
  
 
Any member of the ''plugdev'' group should now be able to run OpenOCD without using ''sudo''.
 
Any member of the ''plugdev'' group should now be able to run OpenOCD without using ''sudo''.

Revision as of 04:30, 9 April 2022

On Linux, OpenOCD requires superuser privileges to communicate with your USB drivers. You can give OpenOCD superuser priveleges with the sudo command, like this:

sudo openocd [-f ...]

...but sudo prompts the user for the root password. Suppose you want to allow a user to run OpenOCD without a root password, or you just don't want to type sudo each time you run OpenOCD. This guide will demonstrate how to configure Ubuntu Linux to allow a particular user to run OpenOCD for a device without sudo.

Step 1: Add the User to the plugdev Group

Determine if the user is part of the plugdev group with the groups command. Open a terminal window and type:

groups USERNAME

...replacing USERNAME with the name of the user account. The groups command will print a list of all of the user's groups. Look for the group plugdev. If the user is not already a member of plugdev, add the user with the adduser command:

sudo adduser USERNAME plugdev

Run groups USERNAME again to verify that the user is now part of plugdev.

Step 2: Determine your Device's Vendor ID and Product ID

The vendor ID and product ID for the EK-TM4C123GXL Board adapter are as follows:

idVendor = "1cbe
idProduct = 00fd

For any other device, plug it in, then use the lsusb command to retrieve your hardware's vendor ID and product ID. You will need them below.

Step 3: Add the Device to udev

Now you need to add your hardware to the plugdev group. In the terminal window, navigate to /etc/udev/rules.d and list the contents of the directory.

cd /etc/udev/rules.d
ls

In a fresh installation of Ubuntu 10.04 you should see two files listed: 70-persistent-cd.rules and 70-persistent-net.rules. If you see other files, proceed with caution. If in doubt contact your system administrator. If you are ready to proceed, create a new file in the gedit text editor.

sudo gedit 10-my-usb.rules

You can name this file whatever you want, so long as it ends in ".rules". However, rules files by convention begin with a number. Linux parses rules files in lexical order, and the number makes it easy to see which files will be parsed first. Choosing a low number (like 10, as above) means that your file will be parsed before system rules files.

Add the following text to the file, replacing VENDOR_ID and PRODUCT_ID with the values you found in Step 2 above.

ATTRS{idProduct}=="[PRODUCT_ID]", ATTRS{idVendor}=="[VENDOR_ID]", MODE="666", GROUP="plugdev"

For the EK-TM4C123GXL Board, the text should look like this:

ATTRS{idProduct}=="00fd", ATTRS{idVendor}=="1cbe", MODE="666", GROUP="plugdev"

On older Ubuntu installations you may need to use SYSFS instead of ATTRS, like this:

SYSFS{idProduct}=="00fd", SYSFS{idVendor}=="1cbe", MODE="666", GROUP="plugdev"

Save the file and close it. Now tell Ubuntu to reload udev rules by entering the following in the terminal window:

sudo udevadm trigger

Any member of the plugdev group should now be able to run OpenOCD without using sudo.