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..
/sys/class/dmi/id/product_sku? – Arkadiusz Drabczyk May 29 '19 at 16:48product_serialcontainsTo 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 '19 at 11:10/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 03 '19 at 13:47