31

I've installed the OS and the time is incorrect.

The timedatectl shows:

       System clock synchronized: no
systemd-timesyncd.service active: yes
                 RTC in local TZ: no

How to force it to sync now?

graham
  • 13,061
Velkan
  • 3,681

3 Answers3

47

From man timedatectl, NTP-sync needs to be enabled:

sudo timedatectl set-ntp true

Then timedatectl should do the rest automatically (see Redbob's reply).

If timedatectl does not show "System clock synchronized: yes", check the status of systemd-timesyncd:

systemctl status systemd-timesyncd

and restart it:

sudo systemctl restart systemd-timesyncd

Check the status of timedatectl again:

$ timedatectl
...
       System clock synchronized: yes
systemd-timesyncd.service active: yes
                 RTC in local TZ: no
mhck
  • 105
N0rbert
  • 103,263
6

It worked for me, when I edited /etc/systemd/timesyncd.conf, because lines below were commented. I uncommented them and changed NTP and FallbackNTP lines by my Network servers:

[Time]
NTP=172.24.3.1
FallbackNTP=172.24.44.51
RootDistanceMaxSec=5
PollIntervalMinSec=32
PollIntervalMaxSec=2048

After that, I restarted systemd-timesyncd.service, so System clock synchronized status turned to yes

Redbob
  • 1,686
0

System clock synchronization depends on a number of factors:

  1. timedatectl NTP-sync must be enabled
  2. /etc/systemd/timesyncd.conf must be properly configured
  3. systemd-timesyncd may need to be unmasked
  4. systemd-timesyncd must be running and restarted after changes (including changes to /etc/systemd/timesyncd.conf or changes to the masking)

To enable timedatectl NTP-sync:

$ sudo timedatectl set-ntp true

I have seen /etc/systemd/timesyncd.conf differ on different installs of Ubuntu. On some installs, the [Time] section of /etc/systemd/timesyncd.conf is commented out.

  • At a minimum, uncomment NTP and RootDistanceMaxSec in /etc/systemd/timesyncd.conf
  • RootDistanceMaxSec may need to be increased (e.g. 30, see this StackExchange post)

/etc/systemd/timesyncd.conf:

...
[Time]
NTP=192.168.1.1
FallbackNTP=ntp.ubuntu.com
RootDistanceMaxSec=30
PollIntervalMinSec=32
PollIntervalMaxSec=2048

Unmask systemd-timesyncd:

sudo systemctl unmask systemd-timesyncd

Restart systemd-timesyncd after changes and check its status:

sudo systemctl restart systemd-timesyncd
systemctl status systemd-timesyncd

systemd-timesyncd should be enabled and active (running):

● systemd-timesyncd.service - Network Time Synchronization
     Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2024-08-31 14:52:32 EDT; 1 months 14 days ago
     ...

Now timedatectl should show the system clock is synchronized:

$ timedatectl
               Local time: Tue 2024-10-15 05:19:07 EDT
           Universal time: Tue 2024-10-15 09:19:07 UTC
                 RTC time: Tue 2024-10-15 09:19:06
                Time zone: America/Kentucky/Monticello (EDT, -0400)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no
muru
  • 207,228
mhck
  • 105