Skip to content

Instantly share code, notes, and snippets.

@bencord0
Last active August 31, 2023 11:51
Show Gist options
  • Save bencord0/7690953 to your computer and use it in GitHub Desktop.
Save bencord0/7690953 to your computer and use it in GitHub Desktop.
Unique id for a linux system
#!/bin/bash
cat /var/lib/dbus/machine-id && exit
# Provided by dbus, hence available on all systemd systems.
# Any user can read it and it is persistent accross boots.
# It is unique per installation, and works well in VMs.
# Not all systems (i.e. stage3 gentoo/handbook install)
# have dbus installed by default.
cat /sys/class/dmi/id/product_uuid && exit
# Which should be the same as
# dmidecode -s system-uuid
# Requires root
# Persistent accross re-installs
# Depends on x86 hardware
# Not available on all kernels, may be module dependent.
# Lennert Poettering has a good analysis
# http://0pointer.de/blog/projects/ids.html
# FreeBSD has
sysctl kern.hostuuid
# Which is persistent accross reboots
@bencord0
Copy link
Author

What about /etc/machine-id ?

When I wrote this, I don't think systemd was doing that much with machine-id, and the file didn't exist on my system

That isnt true any more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment