<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://sidiprojects.us/w/index.php?action=history&amp;feed=atom&amp;title=Resetting_machine_id_on_debian</id>
	<title>Resetting machine id on debian - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://sidiprojects.us/w/index.php?action=history&amp;feed=atom&amp;title=Resetting_machine_id_on_debian"/>
	<link rel="alternate" type="text/html" href="https://sidiprojects.us/w/index.php?title=Resetting_machine_id_on_debian&amp;action=history"/>
	<updated>2026-04-09T11:08:12Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.38.6</generator>
	<entry>
		<id>https://sidiprojects.us/w/index.php?title=Resetting_machine_id_on_debian&amp;diff=1026&amp;oldid=prev</id>
		<title>David: First version of instructions</title>
		<link rel="alternate" type="text/html" href="https://sidiprojects.us/w/index.php?title=Resetting_machine_id_on_debian&amp;diff=1026&amp;oldid=prev"/>
		<updated>2020-04-03T19:20:02Z</updated>

		<summary type="html">&lt;p&gt;First version of instructions&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;You need a script, and you need a systemd unit file.&lt;br /&gt;
&lt;br /&gt;
=Script=&lt;br /&gt;
Create a a script called refresh_machine_id in /usr/local/bin or somewhere else in $PATH. You can do &amp;lt;pre&amp;gt;$ echo $PATH&amp;lt;/pre&amp;gt; to see your options. Put this in the script:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
# &lt;br /&gt;
# refresh_machine_id&lt;br /&gt;
# ------------------&lt;br /&gt;
# Sets a new machine ID.&lt;br /&gt;
# &lt;br /&gt;
# Some ideas from &lt;br /&gt;
#  github.com/vzhestkov/reset-machine-id/blob/master/reset-host-machine-id.sh&lt;br /&gt;
# &lt;br /&gt;
# author: David&lt;br /&gt;
&lt;br /&gt;
TRIGGER_FILE=&amp;quot;/RESET-HOST-MACHINE-ID&amp;quot;&lt;br /&gt;
&lt;br /&gt;
if [ -f &amp;quot;${TRIGGER_FILE}&amp;quot; ]; then&lt;br /&gt;
   rm &amp;quot;${TRIGGER_FILE}&amp;quot;&lt;br /&gt;
   mv /etc/machine-id /home/YOUR_USERNAME_HERE/etc-machine-id-backup&lt;br /&gt;
   mv /var/lib/dbus/machine-id /home/YOUR_USERNAME_HERE/dbus-machine-id-backup&lt;br /&gt;
&lt;br /&gt;
   dbus-uuidgen --ensure&lt;br /&gt;
   systemd-machine-id-setup&lt;br /&gt;
&lt;br /&gt;
   systemctl disable refresh-machine-id.service&lt;br /&gt;
   systemctl daemon-reload&lt;br /&gt;
&lt;br /&gt;
   reboot&lt;br /&gt;
fi&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This makes backup copies of your old machine-id (be sure to change YOUR_USERNAME_HERE in the above code), changes your machine-id, then disables the service. You can leave the service enabled, if you want to, by removing the two systemctl lines. In that case, you can just use the trigger file to reset the machine ID on the next boot, rather than having to re-enable the service each time.&lt;br /&gt;
&lt;br /&gt;
Next give the script to root, and fix permissions:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ script=&amp;quot;/put/the/path/here/refresh_machine_id&amp;quot;; chown root:root &amp;quot;$script&amp;quot;; chmod 0700 &amp;quot;$script&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You need to do this since you're modifying directories that ordinary users can't modify, and issuing commands with systemctl. &lt;br /&gt;
&lt;br /&gt;
=Unit File=&lt;br /&gt;
&lt;br /&gt;
Next you need to make the unit file so that systemd will call your script once your system starts. Go to /etc/systemd/system, where administrator-added unit files go (unit files from packages go to /lib/systemd/system), and create a file called refresh-machine-id.service. Put this in there:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[Unit]                                                                          &lt;br /&gt;
Description=Refresh the machine ID based on trigger file /RESET-HOST-MACHINE-ID &lt;br /&gt;
Wants=basic.target                                                              &lt;br /&gt;
After=basic.target dbus-org.freedesktop.hostname1.service systemd-hostnamed.service&lt;br /&gt;
                                                                                &lt;br /&gt;
[Service]                                                                       &lt;br /&gt;
Type=oneshot                                                                    &lt;br /&gt;
RemainAfterExit=true                                                            &lt;br /&gt;
ExecStart=/put/the/path/here/refresh_machine_id                             &lt;br /&gt;
                                                                                &lt;br /&gt;
[Install]                                                                       &lt;br /&gt;
WantedBy=multi-user.target                                                      &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This runs the script on start, and waits until it completes. &lt;br /&gt;
&lt;br /&gt;
= Install the service =&lt;br /&gt;
&lt;br /&gt;
Do a couple of things to get the service running. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ sudo systemctl daemon-reload&lt;br /&gt;
$ sudo systemctl enable refresh-machine-id.service&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Check that it's loaded OK with &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ sudo systemctl status refresh-machine-id.service&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Add the trigger file =&lt;br /&gt;
&lt;br /&gt;
The last thing we need to do before running this thing is add the trigger file in the root directory (/) that the script looks for before resetting the machine-id. That's easy:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ sudo touch /RESET-HOST-MACHINE-ID&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now we are ready to try it.&lt;br /&gt;
&lt;br /&gt;
= Check that it worked =&lt;br /&gt;
&lt;br /&gt;
Take note of the values of the machine ID (they should match):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ cat /etc/machine-id&lt;br /&gt;
$ cat /var/lib/dbus/machine-id&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now restart your system. The boot will get to your script, change the machine-id with your script, and reboot. The next boot will be normal. Repeat the commands above to see that the machine-id has changed, and check to be sure that /RESET-HOST-MACHINE-ID no longer exists. Voilá!&lt;/div&gt;</summary>
		<author><name>David</name></author>
	</entry>
</feed>