Managing System Time - date, timedatectl, NTP, chrony

Managing System Time - date, timedatectl, NTP, chrony

What You Will Achieve

  • Show the current time with date and switch between formatting and setting
  • Explain the relationship between the system clock and the hardware clock (RTC) using hwclock
  • Manage time zone and time synchronization together with timedatectl
  • Configure time sync with NTP (ntpd / chrony) and check its state
  • Answer the exam-frequent "UTC vs local time" and "manual setting vs NTP conflict" with reasoning

This is the core of LPIC-1 objective 108.1 "Maintain system time". Log correlation, accurate cron triggering, and TLS certificate validation all depend on correct time.

At Which Layer Is System Time Managed?

Linux time is managed in two layers: the system clock (a software clock kept by the kernel) and the hardware clock (the RTC on the motherboard). Day-to-day synchronization targets the system clock, while the RTC provides the initial value at boot.

Clock Substance Command When powered off
System clock Software clock inside the kernel date / timedatectl Lost
Hardware clock (RTC) Battery-backed chip on the motherboard hwclock Retained

At boot the time is read from the RTC into the system clock (hctosys), and during operation NTP corrects the system clock. Writing the system clock back to the RTC with hwclock --systohc keeps the next boot's initial value accurate.

On systemd systems, reading from and writing back to the RTC at boot is handled automatically, so manual hwclock operations are usually unnecessary. When NTP sync is enabled, timedatectl updates the RTC periodically.

Showing and Setting Time with date

date shows and sets the current system time. Format specifiers starting with + let you shape the output freely. Setting requires root, but avoid manual setting while NTP sync is running.

Showing the time and format specifiers

date
date '+%Y-%m-%d %H:%M:%S'
date '+%Y%m%d'
date -u
Sat May 30 14:23:07 JST 2026
2026-05-30 14:23:07
20260530
Sat May 30 05:23:07 UTC 2026

The main format specifiers are %Y (4-digit year), %m (month), %d (day), %H (hour, 24h), %M (minute), and %S (second). The -u flag shows time in UTC. date '+%Y%m%d' is a staple for generating backup file names.

Setting the time manually

sudo date -s '2026-05-30 14:30:00'
Sat May 30 14:30:00 JST 2026

-s (--set) sets the time directly. However, in environments where NTP sync is enabled, the setting is overwritten by NTP almost immediately. To set it manually, stop synchronization first (see below).

Operating the Hardware Clock with hwclock

hwclock reads and writes the RTC. --systohc copies the system time to the RTC, and --hctosys copies the RTC to the system time. Whether the RTC is kept in UTC or local time is an exam-frequent point.

Reading the RTC and sync direction

sudo hwclock --show
sudo hwclock --systohc
sudo hwclock --hctosys
2026-05-30 14:31:05.123456+09:00

--show (-r) displays the current RTC value. Remember the direction from the name.

Option Direction Purpose
--systohc (-w) System -> RTC Save correct system time to the RTC
--hctosys (-s) RTC -> System Initialize system time from the RTC

UTC vs local time

sudo hwclock --systohc --utc
sudo hwclock --systohc --localtime

With --utc the RTC is treated as UTC; with --localtime it is treated as local time. UTC is strongly recommended for Linux-only systems. Keeping the RTC in local time tends to cause double corrections and drift on DST changes or time zone changes.

On a dual boot with Windows, Windows treats the RTC as local time by default, so either match the Linux side with --localtime or change Windows to use UTC. Mixing the two makes the time drift on every boot.

Managing Time and Time Zone with timedatectl

timedatectl is the standard command on systemd systems, managing time, time zone, time synchronization, and RTC mode in one place. Running timedatectl with no argument returns the same output as status.

Checking the current state

timedatectl status
               Local time: Sat 2026-05-30 14:35:12 JST
           Universal time: Sat 2026-05-30 05:35:12 UTC
                 RTC time: Sat 2026-05-30 05:35:11
                Time zone: Asia/Tokyo (JST, +0900)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no

System clock synchronized and NTP service show the sync state. RTC in local TZ: no indicates the RTC is kept in UTC (the recommended state).

Setting the time zone

timedatectl list-timezones | grep Tokyo
sudo timedatectl set-timezone Asia/Tokyo
Asia/Tokyo

list-timezones lists available time zones, and set-timezone sets one. This updates the /etc/localtime symbolic link (see below).

Enabling time synchronization

sudo timedatectl set-ntp true

set-ntp true enables and starts the first existing network synchronization service (typically systemd-timesyncd on systemd systems). Use false to disable it. To set the time manually, first stop synchronization with set-ntp false.

Keeping the RTC in UTC

sudo timedatectl set-local-rtc 0

set-local-rtc 0 maintains the RTC in UTC (recommended). Setting 1 makes it local time, but the official documentation states that "maintaining the RTC in the local timezone is not fully supported and will create various problems with time zone changes and daylight saving adjustments. If at all possible, keep the RTC in UTC mode."

Which Files Determine the Time Zone?

The system time zone is determined by which file under /usr/share/zoneinfo/ is pointed to by /etc/localtime. Debian-based systems additionally hold the zone name as text in /etc/timezone.

Path Role
/usr/share/zoneinfo/ Storage for all time zone definitions (binary)
/etc/localtime Symbolic link pointing to the system TZ
/etc/timezone Zone name as text (Debian / Ubuntu family)
ls -l /etc/localtime
lrwxrwxrwx 1 root root 30 May 30 14:00 /etc/localtime -> /usr/share/zoneinfo/Asia/Tokyo

Using timedatectl set-timezone keeps this link and /etc/timezone consistent automatically. It is safer than relinking by hand. A temporary, per-user change is also possible with the TZ environment variable.

Synchronizing Time with NTP

NTP (Network Time Protocol) is a protocol that fetches accurate time from upstream servers to correct the system clock. There are three implementations: the classic ntpd, its successor chrony, and the lightweight systemd-timesyncd.

Differences among the three implementations

Implementation Config file Check command Characteristics
ntpd (ntp.org reference) /etc/ntp.conf ntpq -p Long history, abundant documentation
chrony (chronyd) /etc/chrony.conf chronyc sources / chronyc tracking Strong with intermittent connections and VMs
systemd-timesyncd /etc/systemd/timesyncd.conf timedatectl status SNTP client only, lightweight

Running multiple time sync daemons on the same host conflicts with each other, so enable only one.

Checking ntpd

ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*ntp1.example.com 133.243.x.x      2 u   45   64  377    8.123    0.512   0.087
+ntp2.example.com 133.243.x.x      2 u   38   64  377   12.456   -0.231   0.142

ntpq -p (peers) lists the peer servers. A leading * marks the server currently in sync, + marks a sync candidate. reach is the reachability (octal; 377 means the last 8 polls all succeeded), and offset is the time difference from local (milliseconds). Servers are specified with server lines in /etc/ntp.conf.

Checking chrony

chronyc sources
chronyc tracking
MS Name/IP address         Stratum Poll Reach LastRx Last sample
===============================================================================
^* ntp1.example.com              2   6   377    23    +12us[  +18us] +/-   14ms
^- ntp2.example.com              2   6   377    21   -103us[ -103us] +/-   21ms

In chronyc sources, the M column is the source mode (^ is a server), and the S column is the selection state (* means in sync). Stratum is the number of hops from a reference clock, and Reach is the reachability register. chronyc tracking shows sync-quality details such as Reference ID, Stratum, System time (the current offset between the NTP clock and system clock), Last offset, and RMS offset. Servers are specified with server / pool lines in /etc/chrony.conf.

For the exam, remember the mapping: "chronyc sources for time sources, chronyc tracking for sync details" and "ntpq -p lists ntpd's peers". The config file names (/etc/ntp.conf and /etc/chrony.conf) are also frequently asked.

Common Mistakes and Fixes

Time management is prone to conflicts between settings and to confusing UTC with local time. Here are typical cases asked on the exam and seen in practice.

  • Confusing UTC and local time: Writing with --localtime while the RTC is supposed to be in UTC makes the time drift by the time zone offset (9 hours in Japan) on every boot. Standardize on UTC for Linux-only systems.
  • Conflict between NTP and manual setting: Setting the time manually with date -s or hwclock --systohc while NTP sync is running gets overwritten by NTP immediately. To set it manually, first stop sync with timedatectl set-ntp false (or stop the relevant daemon).
  • Running multiple sync daemons at once: Starting both ntpd and chronyd makes them fight over the same port and role, destabilizing sync. Enable only one.
  • Time zone change not taking effect: Editing /etc/localtime by hand but leaving it inconsistent with /etc/timezone (Debian family). Using timedatectl set-timezone keeps both consistent.
  • TZ change not affecting running processes: Even after changing the time zone, already-started daemons (cron, applications) may keep the old TZ. Restart the services after the change.

Troubleshooting

Time sync issues are fastest to isolate in the order "symptom -> cause -> check -> fix".

Symptom: timedatectl does not synchronize (System clock synchronized: no)

Cause: The time sync service is disabled, or the NTP server is unreachable

Check:

timedatectl status
sudo systemctl status systemd-timesyncd

Fix: Enable sync with sudo timedatectl set-ntp true. If it still shows no, check that the firewall is not blocking UDP port 123 and that the server lines in the config file are correct.

Symptom: Time set with date -s reverts immediately

Cause: NTP sync is enabled and overwrites the manual setting instantly

Check:

timedatectl status

Fix: If System clock synchronized: yes, this is normal behavior. To set the time intentionally, stop sync with sudo timedatectl set-ntp false first, then run date -s.

Symptom: Time drifts by the time zone offset on every boot

Cause: The RTC mode (UTC / local) and the system's interpretation disagree

Check:

timedatectl status
sudo hwclock --show

Fix: For Linux-only systems, standardize the RTC on UTC with sudo timedatectl set-local-rtc 0. For a dual boot with Windows, align both sides to one mode.

Completion Checklist

  • [ ] Checked time, TZ, and sync state with timedatectl status
  • [ ] Set the correct time zone with timedatectl set-timezone
  • [ ] Enabled time sync with timedatectl set-ntp true
  • [ ] Verified time source reachability with chronyc sources / ntpq -p
  • [ ] Confirmed the RTC is kept in UTC (set-local-rtc 0)

Summary

Scenario Command Purpose
Show time date '+%Y-%m-%d' Display with a custom format
Check state timedatectl status Check time, TZ, and sync together
Set TZ timedatectl set-timezone Change the time zone
Control sync timedatectl set-ntp true Enable NTP sync
Write back to RTC hwclock --systohc Save system time to the RTC
Check chrony chronyc sources / tracking Time sources and sync quality
Check ntpd ntpq -p List peer servers

System time is the foundation of logs, cron, and certificate validation. After mastering 108.1, combine it with time-dependent log management and job scheduling to complete your operational knowledge.

Next Reading

Continue Your LPIC-1 Journey

LPIC-1 Hub

  • LPIC-1 Learning Hub — Full LPIC-1 article map, progress tracking, and exam objective coverage

Practice