10.1. Configuring System Time

Debian tracks time in three layers: a battery-backed hardware clock that keeps time while the machine is off, a kernel system clock that everything on the running system actually reads, and a time zone setting that converts the kernel's UTC seconds into the local time people and programs display. This section establishes how the three relate, how to inspect and change them safely, and what is different in virtual machines and intermittently connected systems.

10.1.1. System Clock, Hardware Clock, UTC, and Time Zones

The kernel's system clock counts seconds since 1970-01-01 UTC, driven by a hardware counting source - a TSC or HPET on physical hardware, or a paravirtual clock provided by the hypervisor in a virtual machine. It is the only clock running software reads. The hardware clock (RTC) exists to bootstrap that count at power-on: the kernel reads it once during boot, and from then on the RTC is a backup, written back periodically while the system clock is synchronized. The time zone is not part of any clock - it is a display rule applied when converting UTC to local time. Figure 10.1 shows the relationships.

Clock layers

Figure 10.1. Conceptual view of the clock layers. The NTP daemon and the RTC both feed the kernel system clock; the time zone only converts what is displayed. In a virtual machine the RTC is an emulated device and the counting source is paravirtual, but the layering is the same.

timedatectl summarizes all three layers at once. On clock, as john:

$ timedatectl
               Local time: Thu 2026-11-19 23:53:22 UTC
           Universal time: Thu 2026-11-19 23:53:22 UTC
                 RTC time: Thu 2026-11-19 23:53:22
                Time zone: Etc/UTC (UTC, +0000)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no

Local and Universal time are identical because the zone is Etc/UTC; RTC time is what the hardware clock holds, shown without a zone because the RTC just stores a count; System clock synchronized: yes means a time synchronization service has disciplined the clock; NTP service: active says such a service is running (chrony here); RTC in local TZ: no is the recommended state - the RTC stores UTC. Chapter 2 checked exactly this panel at first boot in Section 2.5.1.

timedatectl subcommand Description
(no arguments) Print the clock summary shown above.
show -p PROPERTY Print selected properties, as in show -p NTP.
set-time "Y-M-D H:M:S" Set the system clock; refused while a sync service is active.
set-timezone ZONE Change the system time zone.
list-timezones List available zone names, one per line.
set-local-rtc 1 or 0 Record whether the RTC stores local time or UTC.
set-ntp true or false Enable or disable the time synchronization service.
timesync-status Detailed client status; works only with systemd-timesyncd (Section 10.2.2).

The date command displays and, as root, sets the system clock. With no arguments it shows local time; -u shows UTC; a TZ variable overrides the zone for that one invocation without touching any configuration:

$ date
Thu Nov 19 23:53:24 UTC 2026
$ date -u
Thu Nov 19 23:53:26 UTC 2026
$ TZ=America/New_York date
Thu Nov 19 18:53:28 EST 2026

The same instant, rendered three ways: the system clock did not move between the three commands; only the display rule changed. That is the whole mechanism of time zones on Linux - per-process TZ, or the system-wide setting stored as a symlink:

$ readlink /etc/localtime
../usr/share/zoneinfo/Etc/UTC

/etc/localtime points into the compiled zone database under /usr/share/zoneinfo; on this Debian 13 system that symlink is the entire record of the configured zone (older tooling sometimes mentions an /etc/timezone text file; timedatectl manages the symlink, and changing the zone does not create one). Change the zone and check the result with the same views as before:

$ sudo timedatectl set-timezone America/New_York

The command prints nothing; the change is immediate. Verify:

$ timedatectl
               Local time: Thu 2026-11-19 18:53:34 EST
           Universal time: Thu 2026-11-19 23:53:34 UTC
                 RTC time: Thu 2026-11-19 23:53:34
                Time zone: America/New_York (EST, -0500)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no
$ readlink /etc/localtime
../usr/share/zoneinfo/America/New_York
$ date
Thu Nov 19 18:53:37 EST 2026
$ date -u
Thu Nov 19 23:53:39 UTC 2026

Local time moved five hours back, Universal time did not move, and the RTC line still tracks UTC - exactly the separation in Figure 10.1. Restore the UTC zone before continuing:

$ sudo timedatectl set-timezone Etc/UTC

Silent again; readlink /etc/localtime would show the Etc/UTC target once more.

The hardware clock is read with hwclock. Reading the RTC device requires root, so this is a sudo command from john's shell:

$ sudo hwclock --show
2026-11-19 23:53:43.227343+00:00
hwclock option Description
--show Read the RTC and print it; needs root.
--systohc Copy the system clock into the RTC.
--hctosys Copy the RTC into the system clock (what boot does before NTP starts).

On a synchronized system you rarely need to write the RTC by hand: the kernel periodically copies the system clock back to the RTC while the clock is disciplined (the "eleven-minute mode"), and chrony's rtcsync configuration directive enables that behavior explicitly. Section 10.1.2 shows the manual write anyway, because it is the right tool when no synchronization service is running.

The one setting to treat carefully is RTC in local TZ. Storing local time in the RTC is a compatibility hack for machines that dual-boot an operating system which writes local time into it; the installer's UTC question in Section 2.4.3 was about exactly this. Switching modes to see what it looks like:

$ sudo timedatectl set-local-rtc 1 --adjust-system-clock
Warning: The system is now being configured to read the RTC time in the local time zone
         This mode cannot be fully supported. It will create various problems
         with time zone changes and daylight saving time adjustments. The RTC
         time is never updated, it relies on external facilities to maintain it.
         If at all possible, use RTC in UTC

The warning is the tool's own: with the zone set to Etc/UTC this particular switch changes nothing numerically, but on a machine in a non-UTC zone the RTC would then be interpreted as local time, and every daylight-saving transition corrupts that interpretation by an hour. The mode switch is recorded in /etc/adjtime:

$ cat /etc/adjtime
0.000000 1795131751 0.000000
1795131751
LOCAL

The first two lines record calibration history; the third - LOCAL instead of UTC - is what boot reads to interpret the RTC. Keep Linux-only systems on UTC, and use local RTC mode only for a dual-boot machine, decided at the installer question in Section 2.4.3. Undo the experiment:

$ sudo timedatectl set-local-rtc 0

Also silent; the verification, trimmed to the fields that changed - the pipeline sends timedatectl's output through tail -n 4, keeping the last four lines:

$ timedatectl | tail -n 4
                Time zone: Etc/UTC (UTC, +0000)
System clock synchronized: no
              NTP service: active
          RTC in local TZ: no

Two things are worth noticing: RTC in local TZ: no again, and System clock synchronized: no - reprogramming the clock cleared the kernel's synchronized flag, and it stays cleared until the NTP daemon re-establishes it. That is normal after any manual clock adjustment, not damage.

10.1.2. Setting Time and Inspecting Clock State

A system with a running synchronization service does not need its clock set by hand, and timedatectl enforces that division of ownership. Try to set the clock while chrony is active:

$ sudo timedatectl set-time '2026-11-19 22:30:00'
Failed to set time: Automatic time synchronization is enabled

The command fails without touching anything: while a sync service owns the clock, a second writer would fight it. To set the clock manually - which makes sense on an isolated machine, or while diagnosing a broken sync setup - first stop the service:

$ sudo timedatectl set-ntp false

Silent, but the summary shows the change:

$ timedatectl
               Local time: Thu 2026-11-19 23:53:51 UTC
           Universal time: Thu 2026-11-19 23:53:51 UTC
                 RTC time: Thu 2026-11-19 23:53:51
                Time zone: Etc/UTC (UTC, +0000)
System clock synchronized: no
              NTP service: inactive
          RTC in local TZ: no

NTP service: inactive - chrony is stopped, and with it the discipline of the clock.

On a production system with running databases, replication, or TLS services, do not step the clock by hand: certificate validation, lease expiries, and log ordering can all break on a large jump. Small corrections on a test machine, as here, are harmless and demonstrate the mechanism.

$ sudo date -s "+5 seconds"
Thu Nov 19 23:53:58 UTC 2026
date option Description
-u Show (or set) UTC rather than local time.
-s SETSTRING Set the system clock to SETSTRING; prints the resulting time. Needs root.
+FORMAT Control output, as in the date -u +%FT%TZ stamps the scripts in this chapter write.

date -s prints the time it just wrote - the clock now reads five seconds ahead of where it was. Confirm from john's shell:

$ date
Thu Nov 19 23:54:00 UTC 2026

Now write the corrected clock into the RTC so the next boot inherits it (needed here only because no synchronization service is running at this moment; a synchronized system does this by itself):

$ sudo hwclock --systohc

This prints nothing - it is a device write, not a report. Read the RTC back to verify:

$ sudo hwclock --show
2026-11-19 23:54:02.508578+00:00

The RTC now carries the five-seconds-ahead time. Hand the clock back to the synchronization service and wait for it to re-establish the synchronized state:

$ sudo timedatectl set-ntp true

Silent; chrony starts again. The command below asks chrony's control tool to poll until the clock is synchronized - up to 20 tries, 0.05 seconds apart (chronyc is introduced fully in Section 10.2.3):

$ sudo chronyc waitsync 20 0.05
try: 1, refid: 7F7F0101, correction: 0.000000000, skew: 0.000
try: 2, refid: 179F10C2, correction: 0.000709084, skew: 11.660

Two tries were enough: on the second, chrony had selected a reference (its refid changed from the initial unsynchronized marker) and the clock was back under discipline. The final check:

$ timedatectl
               Local time: Thu 2026-11-19 23:54:10 UTC
           Universal time: Thu 2026-11-19 23:54:10 UTC
                 RTC time: Thu 2026-11-19 23:54:10
                Time zone: Etc/UTC (UTC, +0000)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no

System clock synchronized: yes again, with chrony running. Note what this flag records: that the clock has been synchronized - a statement about the past, which matters when diagnosing an unreachable time server in Section 10.2.4.

10.1.3. Clock Errors in Guests and Intermittently Connected Systems

Virtual machines keep time differently from physical hardware, and knowing which environment you are in prevents a class of confused diagnosis. Identify the environment and the counting source, on clock as john:

$ systemd-detect-virt
kvm
$ cat /sys/devices/system/clocksource/clocksource0/current_clocksource
kvm-clock

In a root shell on clock (sudo -i from john's shell), the kernel's own boot messages confirm the choice - the pipeline filters the kernel ring buffer for the kvm-clock lines and keeps the first three:

# dmesg | grep -i "kvm-clock" | head -n 3
[    0.000000] kvm-clock: Using msrs 4b564d01 and 4b564d00
[    0.000002] kvm-clock: using sched offset of 5427698235 cycles
[    0.000004] clocksource: kvm-clock: mask: 0xffffffffffffffff max_cycles: 0x1cd42e4dffb, max_idle_ns: 881590591483 ns

Leave the root shell with exit. Two consequences follow. First, the system clock is driven by the hypervisor's own notion of time (kvm-clock), not by an oscillator the guest owns - normally an advantage, but it means a paused guest, a suspended host, or a snapshot resume leaves the guest's clock wrong by exactly the paused duration until a synchronization service corrects it. Second, the RTC inspected with hwclock above is the hypervisor's emulated device, not a battery-backed chip: the commands, files, and modes are identical, but physical-RTC behaviors such as slow drift while powered off follow the host's storage of that emulated device. For a KVM guest the practical rule is simple: keep a synchronization service running, and treat a clock that jumped after a pause or resume as a job for chrony or systemd-timesyncd rather than for date -s.

Intermittently connected systems - a laptop that suspends overnight, a machine on a metered or unreliable link - face the same correction problem in slower motion: the clock drifts while unsynchronized, and the first task after connectivity returns is to correct it, possibly by a step rather than a gentle adjustment. The synchronization side is Section 10.2's business; the scheduling side has its own half of the bargain, because a machine that was off at the scheduled moment has missed work that still needs doing: systemd timers catch up one missed calendar run with Persistent=true (Section 10.3.3), and anacron exists precisely for day-granular jobs on machines that are not always running (Section 10.4.3). Accurate time also has consumers beyond scheduling: TLS certificate validation fails on wildly wrong clocks, Kerberos requires it (Chapter 35 treats it as a prerequisite), and log correlation across systems (Chapter 8) is only as good as the worst clock involved.