Getting BBB serial number without using sudo

147 views
Skip to first unread message

Luther Goh Lu Feng

unread,
Mar 4, 2018, 9:40:08 PM3/4/18
to BeagleBoard
As shared by Robert [1], the command to retrieve the serial number is as follows: 

sudo hexdump -e '8/1 "%c"' /sys/bus/i2c/devices/0-0050/eeprom -n 28 | 
cut -b 5-28 

Is there anyway to get the serial number without using sudo? My use case is that I wish to let other programs use the serial number, but I do not wish for these progams to have sudo privilege. What are the possible approaches?

Stuart Longland

unread,
Mar 4, 2018, 9:44:34 PM3/4/18
to beagl...@googlegroups.com
On 05/03/18 12:40, 'Luther Goh Lu Feng' via BeagleBoard wrote:
> As shared by Robert [1], the command to retrieve the serial number is as
> follows: 
>
> sudo hexdump -e '8/1 "%c"' /sys/bus/i2c/devices/0-0050/eeprom -n 28 | 
> cut -b 5-28 
>
> Is there anyway to get the serial number without using sudo? My use case
> is that I wish to let other programs use the serial number, but I do not
> wish for these progams to have sudo privilege. What are the possible
> approaches?

You could make a script, /usr/local/bin/getserial:

#!/bin/sh
hexdump -e '8/1 "%c"' /sys/bus/i2c/devices/0-0050/eeprom -n 28 | cut -b 5-28

Create a group of users allowed to see the serial
# groupadd serialnumber

Then in /etc/sudoers:
@serialnumber ALL = NOPASSWD:/usr/local/bin/getserial

Any user in @serialnumber, is allowed to run /usr/local/bin/getserial
via `sudo`, but `sudo` will reject anything else.
--
Stuart Longland (aka Redhatter, VK4MSL)

I haven't lost my mind...
...it's backed up on a tape somewhere.

Robert Nelson

unread,
Mar 4, 2018, 9:45:06 PM3/4/18
to Beagle Board


On Mar 4, 2018 8:40 PM, "'Luther Goh Lu Feng' via BeagleBoard" <beagl...@googlegroups.com> wrote:
As shared by Robert [1], the command to retrieve the serial number is as follows: 

sudo hexdump -e '8/1 "%c"' /sys/bus/i2c/devices/0-0050/eeprom -n 28 | 
cut -b 5-28 

Is there anyway to get the serial number without using sudo? My use case is that I wish to let other programs use the serial number, but I do not wish for these progams to have sudo privilege. What are the possible approaches?

So cache it..  read once as root at startup and store it somewhere readable, /tmp/....

Regards,

Reply all
Reply to author
Forward
0 new messages