How to get CPU serial under Linux without root permissions

50.9k views Asked by At

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?

7

There are 7 answers

3
Foo Bah On

Have you checked dmesg? Its in /bin

8
Marc B On

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.

1
CanSpice On

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...?

1
Quinn Bailey On

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

1
ETech On

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
0
delverdl On

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.

0
Kaz On

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.