1

I am trying to get a unique system identifier. During research I stumbled on the system serial number which is exactly what I need (also present on the computer case). The serial number is written in the file located in sysfs: /sys/class/dmi/id/product_serial. Executing ls shows that the file is read protected and owned by root:

-r-------- 1 root root 4096 Mai 29 16:00 product_serial

I can't therefore write to it (which is perfect) and I also can't read it without sudo which my program cannot be executed under.

If I change the ownership of this file to my user (which is in sudo group), then I can read it also with my program without using sudo. But this is overwritten with each reboot.

My question is: can reading of this file (serial number) be done without using sudo? Is there perhaps another way to get the serial number that I'm missing?

Is there perhaps a udev rules that could change the ownership? I have seen that hal existed and did exactly what I'd like, but support what dropped in favor of udev. I also thought about reading the information with sudo at system startup and saving it somewhere else, but this way the file would then be changeable... Also there is dmidecode but also needs sudo for accessing this file..

  • Do you have /sys/class/dmi/id/product_sku? – Arkadiusz Drabczyk May 29 at 16:48
  • BTW, these are just BIOS entries. After reflashing my BIOS with images from the original BIOS maker, my product_serial contains To Be Filled By O.E.M. ... So if you are a looking for a waterproof way to get a unique system identifier, this is not it. Also, for a certain type of VM, you'd probably get the same value in each VM. – dirkt May 30 at 11:10
  • @ArkadiuszDrabczyk no, this entry is not there – maetulj Jun 3 at 8:09
  • @dirkt exactly, those values are read from SMBIOS. I am aware this option is not available for all vendors, but I am using only one vendor which has this entry defined (sample size: ~10, its ok for me :) I would prefer this for identification since this number is also present on the case of the computer so that I can easily match it to the virtual space... – maetulj Jun 3 at 8:14
  • And see here for a discussion how to change permissions in /sys - TL;DR there doesn't seem to be a canconical way, but there are workarounds. An alternative would be a suid root program which just reads this entry. – dirkt Jun 3 at 13:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.