25

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
  • 10,436
Velkan
  • 3,616

2 Answers2

40

From man timedatectl all you need is to enable NTP-sync.

sudo timedatectl set-ntp true

then it do the rest automatically.

If it does not work check status of systemd-timesyncd.service

systemctl status systemd-timesyncd.service

and restart it

sudo systemctl restart systemd-timesyncd.service

And then check again:

$ timedatectl
...
       System clock synchronized: yes
systemd-timesyncd.service active: yes
                 RTC in local TZ: no
N0rbert
  • 99,918
  • 4
    The status of systemd-timesyncd.service was useful - helped to see the problem with the server connectivity. – Velkan Jul 24 '18 at 09:22
  • On Ubuntu 18.04 this doesn't work... can someone please verify? – lewis4u Jun 13 '19 at 11:08
  • @lewis4u: it works for me in Ubuntu18.04, the systemctl part. Does your firewall allow you to access the NTP servers? – HongboZhu Jul 02 '19 at 14:18
  • @lewis4u: are time servers configured? can you check /etc/systemd/timesyncd.conf ? You can see what time servers are used using the above systemctl status command. Indeed, on my 18.04 synchronization was off and setting set-ntp to on did not work until I set time servers. – Nik O'Lai Aug 23 '19 at 12:23
  • Inside time servers everything is commented out... only [Time] is not – lewis4u Aug 23 '19 at 13:00
  • 3
    Even after restarting systemd-timesynd.service, timedatectl still reports System clock synchronized: no. Does anyone know why this would be? – snark Sep 26 '19 at 13:28
  • @snark: There is a missing step here. You must have ntp installed, which it is not by default. sudo apt install ntp, then reboot. – President James K. Polk Mar 19 '20 at 14:55
  • 2
    @PresidentJamesMoveonPolk: At least on Ubuntu 20.04, ntp conflicts with systemd-timesyncd and wants to remove it. It must be something else. In my case, the error was a typo in the NTP configuration. – emk2203 Apr 23 '20 at 12:37
  • What should I do for it to start automatically start in reboot? – alper Nov 28 '21 at 21:47
  • systemctl status systemd-timesyncd.service Unit systemd-timesyncd.service could not be found. – inquisitive Jun 28 '22 at 07:38
  • Failed to restart systemd-timesyncd.service: Unit systemd-timesyncd.service is masked. It does not work – maiky Jan 19 '23 at 13:12
  • @maiky If and when a service is masked, you can always unmask it. Like, sudo systemctl unmask systemd-timesyncd – mchid Jun 26 '23 at 08:19
  • @maiky However, it won't automatically start when you boot the system unless it's enabled: sudo systemctl enable systemd-timesyncd and of course, to prevent it from automatically starting while leaving you the option to manually start and call the service, you can disable it but leave it unmasked: sudo systemctl disable systemd-timesyncd – mchid Jun 26 '23 at 08:20
5

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,596