Linux下无root权限如何获取CPU序列号
在没有root权限的Linux(Ubuntu)下如何获取CPU序列号?
我尝试了 cpuid 命令,它无需 root 权限即可工作,但似乎返回全零(我相信是因为需要在 BIOS 中更改某些内容)。
您能否建议我另一种从程序中检索 CPU 序列号的方法,无需 root 权限且无需修改 BIOS?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
处理器序列号基本上仅存在于 Pentium III 处理器中。由于提出的隐私问题,英特尔从后来的型号中删除了它。因此,除非您使用的是 PIII 并且您的 BIOS 设置允许您读取序列号,否则您将得到的只是 0。
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.
需要root权限。答案是dmidecode。
如果您需要 CPU ID:
这将获取 CPU ID,从输出中删除“ID:”
如果您需要接收计算机ID:
如果您希望在没有root权限的情况下获得内核uuid,那么:
这是因为最近的评论。很久以前发生的事情,所以现在无法解释为什么这些 ID 被用作机器标识符。从
处理器信息
部分获取实际的处理器ID。在 Debian 操作系统上提取。Root permissions required. The answer is dmidecode.
If you need CPU ID:
This will get CPU ID, remove 'ID: ' from output
If you need to receive a computer ID:
If you wish to get kernel uuid without root permissions, then:
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.将许可证与其可执行文件安装到用户文件系统时获得的索引节点号联系起来。如果他们被转移到其他地方,他们就会改变。
缺点是如果必须从备份恢复程序,则可能无法保留这些数字。
我以前也做过这样的事。您必须非常慷慨地让真正的用户在更改硬件时激活许可证。
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.
无论我是否使用 sudo,
cpuid
都会为我返回相同的序列号:除非您指的是其他序列号...?
cpuid
returns the same serial number for me regardless of my use ofsudo
:Unless there's some other serial number that you're referring to...?
正如之前提出这个问题时所建议的,如果您尝试使用它进行许可(因为您使用了许可标签),您可能需要尝试 MAC 地址:
CPU 序列号
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
这可能与发行版相关,但请尝试
并检查序列,如下所示:
在没有超级用户的情况下在 Raspbian GNU/Linux 11(牛眼)上测试。
This is likely distro-dependent, but try
And check for the serial as in:
Tested on Raspbian GNU/Linux 11 (bullseye) without super user.
CPU没有序列号;也许您想要没有 root 权限的 DMI 基本信息(这只会显示您的主板制造商和型号的持久 ID,但没有序列号):
否则您可以“告诉”dmidecode 从非特权运行用户:
然后您可以运行例如:
在大多数情况下,“系统序列号”类似于“机箱序列号”或“底板序列号”。请记住,并非所有发行版都安装了此程序,例如,基于 Debian 的系统都有一个以它命名的软件包。
否则,您可以通过系统磁盘找到唯一且持久的、安装后的系统 ID;为此,您可以运行以下命令:
前者将为您提供安装系统的设备路径(对于我的操作系统,它返回/dev/sda7),然后您可以使用以下命令找到它的ID: 因此,
从系统硬盘查找唯一 ID 的完整命令可能是:
我希望这可以满足您或其他人的需求。命令 cut -b 6-8 可能不可移植,因为我假设块设备名称为三个字符长;此外,/dev/disk/by-id/ 路径仅由 UDEV 托管系统填充,并非所有 Linux 发行版都使用它,但我向您保证前者可以在 Ubuntu 中工作。
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):
Otherwise you could "tell" dmidecode to run from unprivileged user:
Then you could run for instance:
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:
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:
So the complete command to find a unique ID from your system's hard disk could be:
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.
您检查过
dmesg
吗?它在/bin
中Have you checked
dmesg
? Its in/bin