Loading...

Lab 78: Managing Time with timedatectl

Inspect and manage system time configuration using timedatectl on a systemd-based host. Verify timezone and NTP state, switch to UTC for consistent logs, perform a controlled manual time set, then restore synchronization.

time systemd troubleshooting

Scenario

You need to confirm a host’s clock settings and adjust them for a troubleshooting workflow. The system uses systemd and may rely on NTP to maintain accurate time. Your job is to inspect time state, switch the host to UTC, temporarily disable NTP, set a manual time value, then restore synchronization.

Operator context

Time changes can impact logs, certificates, scheduled jobs, and time-sensitive applications. Keep changes scoped and reversible, and re-enable synchronization when you are done.

Objective

  • Display current time, timezone, and NTP sync state with timedatectl.
  • Change timezone to UTC.
  • Disable NTP synchronization temporarily.
  • Manually set system time to a known value.
  • Re-enable NTP synchronization and confirm health.

Concepts

  • timedatectl provides a single view of local time, UTC time, timezone, RTC settings, and NTP status.
  • UTC on servers reduces ambiguity across regions and standardizes logs.
  • Manual time sets require NTP to be disabled; otherwise an active NTP client may immediately override the change.
  • Time changes have a blast radius: TLS, Kerberos, cron/systemd timers, and log correlation.

Walkthrough

Step 1 : Display current time and date settings.
Command
timedatectl

This is the fastest way to confirm timezone, UTC time, RTC configuration, and whether the system thinks it is synchronized.

Local time: Tue 2025-07-29 09:34:15 EDT
Universal time: Tue 2025-07-29 13:34:15 UTC
RTC time: Tue 2025-07-29 13:34:14
Time zone: America/New_York (EDT, -0400)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
Step 2 : Change timezone to UTC.
Command
sudo timedatectl set-timezone UTC

Many production environments run in UTC to keep timestamps consistent across regions and simplify incident response.

Time zone set to UTC.
Step 3 : Disable NTP synchronization.
Safety note

Disabling NTP removes automatic correction and can introduce drift. Only disable it for controlled troubleshooting or when you must set time manually.

Command
sudo timedatectl set-ntp false

NTP must be off before manual changes. If time sync remains enabled, your manual set may be overwritten.

NTP synchronization disabled.
Step 4 : Set a controlled manual time value.
Command
sudo timedatectl set-time "2025-07-29 10:00:00"

Setting a full timestamp is clearer and easier to verify than time-only updates. Keep manual offsets short-lived and revert to synchronization when finished.

Time set to 2025-07-29 10:00:00.
Step 5 : Re-enable NTP synchronization.
Command
sudo timedatectl set-ntp true

Restore synchronization so the host converges back to accurate time automatically. After re-enabling, re-check state with timedatectl.

NTP synchronization enabled.
Step 6 : Confirm final time state.
Command
timedatectl

Confirm timezone and synchronization are in the expected state before closing the incident or handing off.

# Confirm:
# Time zone: UTC
# NTP service: active
# System clock synchronized: yes

Common breakpoints

timedatectl set-time fails even with sudo

Confirm NTP is disabled first (timedatectl should show NTP service: inactive or synchronization disabled). If a separate time service is enforcing sync (chrony, timesyncd), stop it temporarily and retry.

NTP enabled but System clock synchronized stays "no"

The service may be active but not synchronized yet. Validate network access, DNS resolution for time sources, and review time service logs. On chrony systems, check chronyc tracking and chronyc sources -v.

Logs become confusing after timezone changes

Changing timezone changes how timestamps render. When troubleshooting, note the time of change and use UTC as your standard to reduce ambiguity.

Cleanup checklist

Ensure the host is back in a safe steady state: UTC configured (if that is your standard) and synchronization enabled.

Commands
timedatectl
sudo timedatectl set-timezone UTC
sudo timedatectl set-ntp true
Success signal

Time zone: UTC, NTP is enabled, and the system reports synchronization is healthy.

Reference

  • timedatectl : Displays current time, timezone, RTC status, and NTP synchronization state.
  • timedatectl set-timezone <TZ> : Sets the system timezone.
    • UTC : Common server standard for consistent timestamps.
  • timedatectl set-ntp true|false : Enables or disables systemd-managed NTP synchronization.
    • true : Enables synchronization.
    • false : Disables synchronization for controlled manual changes.
  • timedatectl set-time "<YYYY-MM-DD HH:MM:SS>" : Sets system time manually (requires NTP disabled).
    • Use a full timestamp for clarity when capturing evidence.