1

I want the time to sync, but it's not. I tried running the following commands, but it's still not syncing.

# timedatectl set-ntp off
# timedatectl set-ntp on
# timedatectl status
                      Local time: Fri 2021-08-06 20:01:43 EDT
                  Universal time: Sat 2021-08-07 00:01:43 UTC
                        RTC time: Fri 2021-08-06 20:01:43
                       Time zone: America/New_York (EDT, -0400)
       System clock synchronized: no
systemd-timesyncd.service active: yes
                 RTC in local TZ: no

Edit: More info

systemctl status systemd-timesyncd
● systemd-timesyncd.service - Network Time Synchronization
   Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Sat 2021-08-07 15:26:10 EDT; 58min ago
     Docs: man:systemd-timesyncd.service(8)
  Process: 9351 ExecStart=/lib/systemd/systemd-timesyncd (code=exited, status=238/STATE_DIRECTORY)
 Main PID: 9351 (code=exited, status=238/STATE_DIRECTORY)

journalctl -u systemd-timesyncd

1]: systemd-timesyncd.service: Service has no hold-off time, scheduling restart. 1]: systemd-timesyncd.service: Scheduled restart job, restart counter is at 5. 1]: Stopped Network Time Synchronization. 1]: systemd-timesyncd.service: Start request repeated too quickly. 1]: systemd-timesyncd.service: Failed with result 'exit-code'. 1]: Failed to start Network Time Synchronization.

Running Ubuntu 18.04. Internet works and can browse the internet.

Rucent88
  • 1,978
  • 1
    Which distro and version of Linux are you using? Is is it a desktop or a server. Is the internet connection working? Please edit your question and add these information. – user68186 Aug 06 '21 at 20:29
  • Did you add any NTP servers to the /etc/systemd/timesyncd.conf file to help with synchronization? After I added servers to the NTP= line my timedatectl status now showed yes for sync. – Terrance Aug 06 '21 at 21:08
  • I never edited the default timesyncd.conf file. It is all comments except [Time] – Rucent88 Aug 06 '21 at 21:15
  • what do you get when you run $sudo hwclock is it an accurate time or something else? – j0h Aug 06 '21 at 22:43
  • 1
    See https://askubuntu.com/a/1106011/231142 as they show how to configure the timesyncd.conf file and restart the service. – Terrance Aug 07 '21 at 13:33

3 Answers3

4

Apparently there was a directory permissions bug and it affects multiple distros. The solution is simple.

$ sudo chmod 0700 /var/lib/private
$ sudo systemctl restart systemd-timesyncd
$ sudo timedatectl status

Also, this may or may not be needed:

$ sudo rm -r /var/lib/private/systemd

Source: https://bbs.archlinux.org/viewtopic.php?id=233277

Rucent88
  • 1,978
1
  1. Check you ntp configuration in /etc/ntp.conf

$ cat /etc/ntp.conf

...
pool 0.ubuntu.pool.ntp.org iburst 
pool 1.ubuntu.pool.ntp.org iburst 
pool 2.ubuntu.pool.ntp.org iburst 
pool 3.ubuntu.pool.ntp.org iburst 

edit the file if necessary (nano /etc/ntp.conf)

  1. Run the following command to restart the service

sudo service ntp restart

  1. Lastly, if you have an UFW firewall enabled on your system you will need to open the NTP UDP port 123 for incoming connections:

$ sudo ufw allow from any to any port 123 proto udp

user68186
  • 33,360
  • Failed to restart ntp.service: Unit ntp.service not found It appears not to be installed. I thought systemd was supposed to replace ntp? – Rucent88 Aug 06 '21 at 21:03
  • See this post: https://www.digitalocean.com/community/tutorials/how-to-set-up-time-synchronization-on-ubuntu-18-04 – Carlos Dagorret Aug 06 '21 at 22:02
  • Thanks, but I'd rather not switch to ntp. Perhaps there is a way to get timesyncd to work? – Rucent88 Aug 07 '21 at 07:39
  • The last part helped me. I had to open 123 port in my firewall, not just for incoming but outgoing too – Whip Dec 16 '22 at 13:18
0

Check logs: journalctl -u systemd-timesyncd

My problem was about root distance parameter (I have bad Windows Server sync server). Increase RootDistanceMaxSec from default value 5 to 15 fixed my problem.

https://www.freedesktop.org/software/systemd/man/timesyncd.conf.html

adasiko
  • 409