Skip to content

[Linux deployment SOP] Time synchronization based on systemd-timesyncd

Published: at 04:39 AM

This SOP is for Debian-based Linux distro, which has been tested on Debian 11 / 12. root is recommended during the deployment, so I don’t make use of sudo.

TL, DR

# Uninstall ntp
apt purge ntp
# Install systemd-timesyncd
apt update && apt install systemd-timesyncd
# Backup the original config
cp /etc/systemd/timesyncd.conf /etc/systemd/timesyncd.conf.bak
# Setting new config, you may adjust NTP / FallbackNTP based on the server's location. 
cat <<'EOF' > /etc/systemd/timesyncd.conf
[Time]
# Main NTP
NTP=time.windows.com
# Fallback NTP
FallbackNTP=pool.ntp.org time1.google.com time1.apple.com time.cloudflare.com time.windows.com time.nist.gov
RootDistanceMaxSec=5
PollIntervalMinSec=5
PollIntervalMaxSec=300
ConnectionRetrySec=30
SaveIntervalSec=60
EOF
# Enable now
systemctl enable --now systemd-timesyncd

Then run timedatectl and check if system clock were synchronized:

$ timedatectl
               Local time: Tue 2025-02-11 13:01:00 HKT
           Universal time: Tue 2025-02-11 05:01:00 UTC
                 RTC time: Tue 2025-02-11 05:01:00
                Time zone: Asia/Hong_Kong (HKT, +0800)
System clock synchronized: yes # See here!
              NTP service: active
          RTC in local TZ: no

You may also need the following:

# Setting timezone, replace `Asia/Hong_Kong` to what you need.
timedatectl set-timezone Asia/Hong_Kong
# You can search the timezone you need with:
timedatectl list-timezones

Previous Post
定位 "Future Is Not Send" 错误
Next Post
Rust 计算属性 (computed properties) 最佳实践