It is possible to extract the Linux serial number without using sudo?
I know it is possible to do in Windows: wmic bios get serialnumber
and in
macOS: system_profiler | grep "r (system)"
. Both of them do not require root privileges.
In Linux this can be used: sudo dmidecode -s system-serial-number
, but it needs sudo. Is there another way?
Open the terminal application. Type the following command as root user. sudo dmidecode -s system-serial-number.
Open the terminal application. Type the following command as root user. sudo dmidecode -s system-serial-number.
The DMI table decoder is a command-line tool for Linux systems. It is commonly used to translate a machine's DMI table (System Management BIOS, or SMBIOS) into a human-readable format.
In the meantime, you can also find the system serial number at /sys/devices/virtual/dmi/id/product_serial. ... Requires root to read, but many of the files in /sys/devices/virtual/dmi/id/ are readable by any user.
dmidecode
reads this information from physical memory, using /dev/mem
, which requires root.
The same information is also provided by the Linux kernel via sysfs in a virtual directory, /sys/devices/virtual/dmi/id
.
Unfortunately, someone decided that all information in that virtual directory is open to anyone for reading, just not the serial numbers:
$ ls -l /sys/devices/virtual/dmi/id
-r--r--r-- 1 root root 4096 Nov 25 17:12 bios_date
-r--r--r-- 1 root root 4096 Nov 14 14:59 bios_vendor
-r--r--r-- 1 root root 4096 Nov 25 17:12 bios_version
-r--r--r-- 1 root root 4096 Nov 25 17:12 board_asset_tag
-r--r--r-- 1 root root 4096 Nov 25 17:12 board_name
-r-------- 1 root root 4096 Nov 25 17:12 board_serial
-r--r--r-- 1 root root 4096 Nov 14 14:59 board_vendor
-r--r--r-- 1 root root 4096 Nov 25 17:12 board_version
-r--r--r-- 1 root root 4096 Nov 25 17:12 chassis_asset_tag
-r-------- 1 root root 4096 Nov 25 17:12 chassis_serial
-r--r--r-- 1 root root 4096 Nov 25 17:12 chassis_type
-r--r--r-- 1 root root 4096 Nov 25 17:12 chassis_vendor
-r--r--r-- 1 root root 4096 Nov 25 17:12 chassis_version
-r--r--r-- 1 root root 4096 Nov 25 17:12 modalias
drwxr-xr-x 2 root root 0 Nov 25 17:12 power
-r--r--r-- 1 root root 4096 Nov 14 14:59 product_name
-r-------- 1 root root 4096 Nov 25 17:12 product_serial
-r-------- 1 root root 4096 Nov 14 14:59 product_uuid
-r--r--r-- 1 root root 4096 Nov 14 14:59 product_version
lrwxrwxrwx 1 root root 0 Nov 14 14:59 subsystem -> ../../../../class/dmi
-r--r--r-- 1 root root 4096 Nov 14 14:59 sys_vendor
-rw-r--r-- 1 root root 4096 Nov 14 14:59 uevent
If you can install package hal
(not installed by default on recent Ubuntu versions), this command will work for you as non-root:
lshal | grep system.hardware.serial
system.hardware.serial = '<serial_number>' (string)
This works because package hal
installs the hald
daemon, which runs as root and collects this data, making it possible for lshal
to read it as non-root.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With