{ "id": "time-sync", "title": "System Time & NTP", "category": "sysadmin", "tags": ["ntp", "time", "timedatectl", "timesyncd", "chrony", "drift"], "updated": "2025-07-14", "summary": "Keeping system clocks accurate and diagnosing time drift.", "sections": [ { "heading": "Why System Time Matters", "body": "
Clocks that drift cause more problems than you expect: SSL certificate validation failures, log timestamps that do not correlate across machines, cron jobs that fire at the wrong time, authentication tokens that expire prematurely, and package signature checks that fail.
On a server, time should be correct to within a second. Most NTP implementations keep it within milliseconds.
" }, { "heading": "Checking Current Time Status", "body": "", "code": "timedatectl\n# Shows: local time, UTC time, timezone, NTP sync status, RTC time\n\ntimedatectl show\n# Machine-readable version of the same" }, { "heading": "systemd-timesyncd", "body": "Most Debian/Ubuntu systems ship with systemd-timesyncd as the default NTP client. It is a lightweight SNTP implementation—adequate for most servers.
The default NTP servers are usually fine. If you need to change them—for example, to use an internal NTP server:
", "code": "# /etc/systemd/timesyncd.conf\n[Time]\nNTP=ntp.internal.example.com\nFallbackNTP=0.debian.pool.ntp.org 1.debian.pool.ntp.org" }, { "heading": "chrony (alternative)", "body": "chrony is a more capable NTP implementation. It handles intermittent network connections and large initial offsets better than timesyncd. On systems where accuracy matters:
", "code": "apt install chrony\nsystemctl enable --now chrony\n\nchronyc tracking # current sync status\nchronyc sources -v # configured time sources and their offsets" }, { "heading": "Diagnosing Time Problems", "body": "", "code": "# Is NTP enabled?\ntimedatectl | grep NTP\n\n# Is timesyncd active?\nsystemctl status systemd-timesyncd\n\n# Did a sync happen recently?\njournalctl -u systemd-timesyncd --since \"1 hour ago\"\n\n# What is the current offset?\ntimedatectl timesync-status | grep Offset" }, { "heading": "Setting Timezone", "body": "", "code": "timedatectl list-timezones | grep Europe\ntimedatectl set-timezone Europe/London" } ] }