Fix WSL time drift

There is a bug in WSL2 that causes the clock inside the VM to drift behind the actual clock on the machine.

This can lead to many unexpected issues, ranging from harmless (git commit messages having old timestamps) to severe (SSL connection failures).

We can sync the VM clock using the command

1
sudo hwclock -s

We can also add the command as a cron job every 5-10 minutes to make sure that the clock doesn’t drift too far back.

Read Next

I’m running an experiment for better content recommendations. These are the 3 posts that are most likely to be interesting for you:

  • Dear past me, use the flags
    After tackling the technical hiccup of syncing VM clocks in WSL2, you’ll appreciate the wisdom in learning from past mistakes to avoid future headaches, like the crucial need for update mechanisms and version control in software development.

  • Generate PEM file for any Linux user
    After fixing your WSL2 clock bug, securing your SSH connections with a robust 4096-bit RSA key is the next smart move to enhance your system’s security and efficiency.

  • Get Docker Containers running in a particular network
    After tackling WSL2’s time-sync bug, you’ll appreciate streamlining your Docker workflow with a handy zsh script to monitor your containers efficiently.

All content is licensed under CC BY-NC-SA 4.0. Copying is an act of love - please copy!
More cool websites: Prev | Hotline Webring | Next
Built with Hugo
Theme Stack designed by Jimmy