How to get CPU serial under Linux without root permissions

守給你的承諾、 提交于 2020-01-23 06:12:57

问题


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?


回答1:


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"



回答2:


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.




回答3:


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




回答4:


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




回答5:


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.




回答6:


Have you checked dmesg? Its in /bin




回答7:


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.



来源:https://stackoverflow.com/questions/5045450/how-to-get-cpu-serial-under-linux-without-root-permissions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!