Photo by Moritz Kindler on Unsplash

How to sync ubuntu clock

The problem

Filippo Valle
1 min readApr 17, 2024

--

Recently I noticed that the clock of my ubuntu machine was wrong, and this broke all SSL connections and 2FA code generation

               Local time: mer 2024-03-14 17:26:35 CEST
Universal time: mer 2024-03-14 15:26:35 UTC
RTC time: mer 2024-03-14 23:42:50
Time zone: Europe/Rome (CEST, +0200)
System clock synchronized: no
NTP service: active
RTC in local TZ: no

The solution

Install htpdate and sync the system clock with a ntp server.

You can also use the ntp package, but it may be blocked by your provider.

sudo apt update && sudo apt install htpdate
sudo htpdate -a google.com

Install hwclock which is under the util-linux-extra package!

apt install util-linux-extra

sync with the system clock with the hardware clock

sudo hwclock --systohc

And Finally use timedatectl to verify everything is working fine

               Local time: mer 2024-03-14 17:26:35 CEST
Universal time: mer 2024-03-14 15:26:35 UTC
RTC time: mer 2024-03-14 15:26:35
Time zone: Europe/Rome (CEST, +0200)
System clock synchronized: no
NTP service: active
RTC in local TZ: no

--

--

Filippo Valle
Filippo Valle

Written by Filippo Valle

Interested in physics, ML application, community detection and coding. I have a Ph.D. in Complex Systems for Life Sciences