How to get CPU serial under Linux without root permissions
Asked Answered
J

7

15

How can I get CPU serial number under Linux (Ubuntu) without root permissions?

I tried cpuid command, it works without root permissions, but appears to return all zeros (I believe because something needs to be changed in BIOS).

Can you please suggest me another way to retrieve CPU serial from a program without root permissions and without having to modify BIOS?

Judaea answered 18/2, 2011 at 19:3 Comment(0)
I
9

Processor serial numbers were basically only in Pentium III processors. Intel removed it from later models due to the privacy concerns that were raised. As such, unless you're on a PIII AND your BIOS settings let you read the serial number, all you'll get are 0's.

Iraidairan answered 18/2, 2011 at 19:11 Comment(8)
I'd forgotten about those... Xeons aren't exactly something you stumble over in your average WorstBuy.Iraidairan
Yes but then how other OSes are able to get them? For example WMI on Windows? There must be some workaround for Linux tooJudaea
@Judaea I hate to revive this ancient thread but it shows up on google, and I just wanted to add that the reason you can get to this information on Windows without admin rights, is because Windows uses a kernel driver to expose this information in userland. You could do the same on Linux in many ways, E.g by putting in the Sudo config that dmidecode can be executed without root rights under a specific account, or by writing a system service that exposes this information through an API in userland. Windows also accesses 'privileged' ring 0 information when you request this through WMI.Meimeibers
@Alex: CPU serial number quotes Intel as saying the feature isn't implemented at all: there is no serial number to retrieve. Not just that it requires kernel access. Unless there's some later CPU feature that reintroduced it in another form, like an MSR... Apparently dmidecode is able to get something, but I don't know where from. Do we know for sure it's not just from the motherboard?Overly
@PeterCordes I am not entirely sure how the serial number is established, it could very well be by the motherboard/chipset (e.g in Agesa with new ryzen CPUs), but either way some parts need to know what CPU is in there in order to give it the correct microcode updates, display it in the BIOS, and so forth, which the Desktop Management Interface (DMI) in the motherboard will give you access to indirectly :)Meimeibers
@Alex: A model number that's the same for every CPU coming off a given production line would be sufficient for that (or more specifically, vendor/family/model/stepping), and could even be baked into the lithography. A serial number that's unique to that individual CPU is something else, and doesn't need to exist. (And presumably didn't before Pentium III's PSN feature, while Intel has had updateable microcode since PPro / PII.)Overly
@PeterCordes Oh good point actually, I wouldn't know about the serial, it seems hard to bake that into the die with lithography, you'd need a new mask for every cpu, but perhaps it gets flashed to some tiny bit of nand or part of the same area microcode is stored in while it's tested? or maybe the serial is fake and the same for all of the same model :P no idea tbh!Meimeibers
@Alex: If the serial number is real and actually stored in the CPU, it would likely be programmed by burning "fuses" in some storage space intended for that. (Like PROM: write once, only by external programming). The same place that gets programmed after a die is tested for its frequency/voltage limits to make it an i7-6700k vs. an i5-6600 or whatever, including programming the model string like Intel(R) Core(TM) i7-6700K CPU @ 4.00GHz. (Intel can also fuse off the high half of the SIMD units to make it a Celeron or Pentium, making it usable even if there was a short-circuit defect there.)Overly
C
9

Root permissions required. The answer is dmidecode.
If you need CPU ID:

dmidecode | grep -w ID | sed "s/^.ID\: //g"

This will get CPU ID, remove 'ID: ' from output
If you need to receive a computer ID:

dmidecode | grep -w UUID | sed "s/^.UUID\: //g"

If you wish to get kernel uuid without root permissions, then:

dmesg | grep UUID | grep "Kernel" | sed "s/.*UUID=//g" | sed "s/\ ro\ quiet.*//g"

It's because of recent comment. Happened long time ago, so can't explain now why these ID were taken as machine identifier. Got actual Processor ID fromn Processor Information section. Extracted on Debian OS.

pr=0; dmidecode | while read line; do [ "$line" == "Processor Information" ] && pr=1; [ $pr -eq 0 ] && continue; [ -n "$(echo $line | grep '^ID')" ] && echo $line | awk -F"ID: " '{print $2}' && break; done
Clarkclarke answered 10/4, 2014 at 14:51 Comment(1)
All of those are incorrect. "dmidecode" returns info about most devices in the system, so there will be a lot of noise -- for example, my PC has a PCI express card with ID of "1". But I can guess that the first command was intentded to return "CPUID" -- identical value for all processors of same type. Second command will return motherboard UUID -- while some motherboards do put unique value there, many leave at all zeros, or re-use same UUID. Finally, the last part is not "kernel UUID" (whatever it is) but rather UUID of your system disk, and changes every time you format it.Dieldrin
S
2

Tie the license to the inode numbers that its executable files get when they are installed into the user's filesystem. If they are moved somewhere else, they will change.

The downside is that the numbers may not be preserved if the program has to be restored from a backup.

I've done this sort of thing before. You have to be very generous about letting genuine users activate the license on changing hardware.

Shinleaf answered 10/3, 2012 at 5:16 Comment(0)
B
1

cpuid returns the same serial number for me regardless of my use of sudo:

 % cpuid | grep serial
Processor serial: 0002-0652-0000-0000-0000-0000
 % sudo cpuid | grep serial
Processor serial: 0002-0652-0000-0000-0000-0000

Unless there's some other serial number that you're referring to...?

Brashear answered 18/2, 2011 at 19:12 Comment(1)
Yes I am referring to this exactly - "0000-0000-0000-0000". The first byte is some stepping ID, but the real serial should be behind those zerosJudaea
D
1

As suggested when this question was asked before, if you are trying to use this for licensing (since you used the licensing tag) you may want to try the MAC address: CPU serial number

Decapod answered 18/2, 2011 at 19:13 Comment(1)
Yes I am using MAC address too, but I want more :)Judaea
L
-1

CPUs has no serial number; maybe that you want DMI basic info without root privilege (This will only show you a persistent id of your motherboard manufacturer and model, but no serial number):

dmesg | grep -i dmi: | cut -d ":" -f 2-

Otherwise you could "tell" dmidecode to run from unprivileged user:

sudo chmod +s /usr/sbin/dmidecode

Then you could run for instance:

dmidecode -s system-serial-number

In most cases "system-serial-number" is like either "chassis-serial-number" or "baseboard-serial-number". Remember that not all distros have this program installed, for instance, Debian based systems have a package named after it.

Otherwise you can find a unique and persistent, thro' installs, system ID via your system's disk; to do that you may run the following:

mount | grep "on / type" | awk '{print $1}'

The former will give you device's path where your system is mounted (for my OS it returned /dev/sda7), and then you can find an ID for it with the following:

find /dev/disk/by-id/ -lname "*sda" ! -name "wwn*"

So the complete command to find a unique ID from your system's hard disk could be:

find /dev/disk/by-id/ -lname "*`mount | grep " / " | awk '{print $1}' | cut -b 6-8`" ! -name "wwn*" -printf "%f\n"

I hope this may fit your needs or someone else's in here. Command cut -b 6-8 may not be portable, because I'm assuming block devices names to be three chars long; moreover, /dev/disk/by-id/ path is only filled by UDEV managed systems and not all Linux distros use it, but I ensure you the former will work in Ubuntu.

Leprose answered 7/6, 2019 at 15:9 Comment(0)
B
-2

Have you checked dmesg? Its in /bin

Bakerman answered 18/2, 2011 at 19:7 Comment(3)
I never used it before - it just gave me a bunch of such messages - can you suggest how exactly I should call it to get processor serial:[38988.366706] VFS: busy inodes on changed media. [38990.355161] VFS: busy inodes on changed media. [38990.360004] VFS: busy inodes on changed media. [38992.355334] VFS: busy inodes on changed media. [38992.357489] VFS: busy inodes on changed media.Judaea
dmesg is a ring buffer of kernel messages. after boot, it'll have all the bootup kernel messages, but they'll eventually get pushed out by other system events. There should be a file in /var/log somewhere that contains the boot messages.Iraidairan
@Marc you need to be root to see the /var/log/messages* files, but dmesg is accessible from nonroot usersBakerman

© 2022 - 2024 — McMap. All rights reserved.