As shared by Robert , 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:
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.
So cache it… read once as root at startup and store it somewhere readable, /tmp/…