timedatectl

Control the system time and date

timedatectl [options]{ command}

Query or change the system clock and its settings.
If no Real Time Clock and no network access set-time is needed, otherwise these are configuration items that probably aren't needed.

Use /lib/systemd-firstboot to initialize the system time zone for mounted (but not booted) system images.

[status]Default
Show current settings of the system clock and RTC , including whether network time synchronization is enabled, by systemd-timesyncd.service.
or a different service might synchronize the clock.
> timedatectl status
               Local time: Thu 2019-09-05 18:37:49 EDT
           Universal time: Thu 2019-09-05 22:37:49 UTC
                 RTC time: n/a
                Time zone: America/New_York (EDT, -0400)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no 
--monitor With status monitors systemd-timesyncd.service and updates the outputs. Ctrl+C to terminate
set-ntp 0|1 activate, enable and starts, or disables and stops systemd-timesyncd.service
Same as:
 systemctl enable  --now systemd-timesyncd.service or
 systemctl disable --now systemd-timesyncd.service,
but is protected by a different access policy.

systemd-timesyncd.service also ensures a monotonic clock on systems without RTC even if no network is available. See systemd-timesyncd.service.

set-time ccyy-mm-dd hh:mm:ss system clock and RTC
set-local-rtc 0|10, RTC is Universal Time (prefered). 1, RTC is local time

RTC is synchronized from the system clock.
With --adjust-system-clock system clock is synchronized from the RTC

set-timezone tz Set system and RTC zone time. Alters /etc/localtime symlink.
lrwxrwxrwx 1 root root 36 Jun 26  2019 /etc/localtime -> /usr/share/zoneinfo/America/New_York
See localtime(5)
--no-ask-password 
-H
--host= hostname | user@hostname[:container]
Execute the operation remotely using SSH.
Container names may be enumerated with machinectl -H host
-M
--machine=container
Execute operation on a local container.
--no-pager Do not pipe output into a pager like more
list-timezones List time zones includes:
Africa/Abidjan
Africa/Accra
Africa/Addis_Ababa
…
America/Antigua
America/Araguaina
America/Argentina/Buenos_Aires  
    (Argentina is the only contaninent/country with cities )
…
Europe/Berlin
Europe/Bratislava
…
Pacific/Tongatapu
Pacific/Wake
Pacific/Wallis
UTC(only abbreviation)
-h
--help
 
--version version string and exit.
systemd 232
+PAM +AUDIT +SELINUX +IMA +APPARMOR +SMACK +SYSVINIT +UTMP
+LIBCRYPTSETUP +GCRYPT +GNUTLS
+ACL +XZ +LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD +IDN

Environment

For list-timezones Pager overrides $PAGER. If neither $SYSTEMD_PAGER nor $PAGER are set, a set of $SYSTEMD_PAGER $SYSTEMD_LESS Override the charset passed to less (by default "utf-8", if the invoking terminal is determined to be UTF-8 compatible).
$SYSTEMD_LESSCHARSET

Files

None in Raspberry Pi stretch
/lib/systed/system/systemd-timesyncd.service.d/disable-with-time-daemon.conf
[Unit]
# don't run  timesyncd  if we have another NTP daemon installed  compare NTP deamons
ConditionFileIsExecutable=!/usr/sbin/ntpd (may be in busybox
ConditionFileIsExecutable=!/usr/sbin/openntpd
ConditionFileIsExecutable=!/usr/sbin/chronyd  Seems better
ConditionFileIsExecutable=!/usr/sbin/VBoxService
# @file /lib/systemd/system/systemd-timesyncd.service
[Unit]
Description=Network Time Synchronization
Documentation=man:systemd-timesyncd.service(8)
ConditionCapability=CAP_SYS_TIME
ConditionVirtualization=!container
DefaultDependencies=no
RequiresMountsFor=/var/lib/systemd/clock
After=systemd-remount-fs.service systemd-tmpfiles-setup.service systemd-sysusers.service
Before=time-sync.target sysinit.target shutdown.target
Conflicts=shutdown.target
Wants=time-sync.target

[Service]
Type=notify
Restart=always
RestartSec=0
ExecStart=/lib/systemd/systemd-timesyncd
WatchdogSec=3min
CapabilityBoundingSet=CAP_SYS_TIME CAP_SETUID CAP_SETGID CAP_SETPCAP CAP_CHOWN CAP_DAC_OVERRIDE CAP_FOWNER
PrivateTmp=yes
PrivateDevices=yes
ProtectSystem=full
ProtectHome=yes
ProtectControlGroups=yes
ProtectKernelTunables=yes
MemoryDenyWriteExecute=yes
RestrictRealtime=yes
RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6
SystemCallFilter=~@cpu-emulation @debug @keyring @module @mount @obsolete @raw-io

[Install]
WantedBy=sysinit.target

Examples

     $ timedatectl set-ntp true
           ==== AUTHENTICATING FOR org.freedesktop.timedate1.set-ntp ===
           Authentication is required to control whether network time synchronization shall be enabled.
           Authenticating as: user
           Password: ********
           ==== AUTHENTICATION COMPLETE ===

           $ systemctl status systemd-timesyncd.service
            systemd-timesyncd.service - Network Time Synchronization
              Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled)
              Active: active (running) since Mo 2015-03-30 14:20:38 CEST; 5s ago
                Docs: man:systemd-timesyncd.service(8)
            Main PID: 595 (systemd-timesyn)
              Status: "Using Time Server 216.239.38.15:123 (time4.google.com)."
              CGroup: /system.slice/systemd-timesyncd.service
                      595 /lib/systemd/systemd-timesyncd
           …

systemd-timesyncd , systemd-timesyncd.service

Network Time Synchronization

Exacutable daemon /lib/systemd/systemd-timesyncd

 /lib/systemd/system/time-sync.target
[Unit]
Description=System Time Synchronized
Documentation=man:systemd.special(7)
RefuseManualStart=yes
System service that synchronizes the local system clock with a remote Network Time Protocol (NTP) server.
When the clock is synchronized the modified timestamp on /var/lib/systemd/clock is set.
This is used on boot to set (advance, never retard) the system clock until a Network Time Protocol server can be reached, timedatectl settime is issued ..
The ramifications of this are that files updated and log entries (etc) made before the system clock is set to the actual time will have the time of the last synchroniation before shutdown!
ls -l /var/lib/systemd/clock
-rw-r--r-- 1 systemd-timesync systemd-timesync 0 May 10 07:17 /var/lib/systemd/clock
The NTP servers contacted are determined from timesyncd.conf, the per-link static settings in .network and the per-link dynamic settings received DHCP. See systemd.network(5)

set-ntp enables and starts, or disables and stops

FILES

Timestamp of the last successful synchronization. /var/lib/systemd/clock

See

systemd, hwclock, date, localtime, systemctl, ntpd


timesyncd.conf, timesyncd.conf.d - Network

Time Synchronization

configuration files

/etc/systemd/timesyncd.conf
#  This file (timesyncd.conf) is part of systemd.
#
# Entries in this file show the compile time defaults.
# Defaults can be restored by simply deleting this file.

[Time]
#NTP=
#FallbackNTP=0.debian.pool.ntp.org 1.debian.pool.ntp.org 2.debian.pool.ntp.org 3.debian.pool.ntp.org
/etc/systemd/timesyncd.conf.d/*.conf
/run/systemd/timesyncd.conf.d/*.conf
/usr/lib/systemd/timesyncd.conf.d/*.conf

These configuration files control NTP network time synchronization. See systemd.syntax(5)

Configuration Directories and Precedence

The default configuration is defined at compile time. These are overridden with /etc/systemd/timesyncd.conf.d/*.conf which contains comments showing the defaults .

Packages needing to customize the configuration( why would they ?? ed), install configuration snippets in /usr/lib/systemd/*.conf.d/.

The main configuration file is read first and values may be overriden by subsequent entries.

Files in *.conf.d/ are sorted by their filename, regardless of subdirectories. When multiple files specify the same option, those which accept a

  • single value, the last occurance is used.
  • list of values, entries are collected as they occur in files. To cause files to be processed in a specific order, prefix all filenames including those in subdirectories with a two-digit number and a dash

    To disable a configuration file supplied by the vendor, place a symlink to /dev/null in the configuration directory in /etc/, with the same filename as the vendor configuration file. /etc/ overrides configuration files installed by packages.

    OPTIONS

    These settings are configured in the [Time] section:
    NTP=srv [srv2 … ] NTP server host names or IP addresses, combined with any per-interface NTP servers acquired from systemd-networkd.service contacted all configured system or per-interface servers until one is found that responds.
    The empty string resets the list of NTP servers and assignments. defaults to an empty list.
    FallbackNTP=srv [srv2 … ] NTP server host names or IP addresses to be used as the fallback NTP servers. Any per-interface NTP servers obtained from systemd-networkd.service take precedence over this setting, as do any servers set via NTP . Only used if no other NTP server information is known. When the empty string is assigned, the list of NTP servers is reset, defaults to a compiled in list of NTP servers
    RootDistanceMaxSec=sec Maximum acceptable root distance. Takes a time value (in seconds). Defaults to 5 seconds.
    PollIntervalMinSec=s
    , PollIntervalMaxSec=s
    The minimum and maximum poll intervals for NTP messages.
    PollIntervalMinSec must not be smaller than 16 seconds. default 32
    PollIntervalMaxSec must be larger than PollIntervalMinSec defaults to 2048 .

    /lib/systemd/system/systemd-networkd.service

    [Unit]
    Description=Network Service
    Documentation=man:systemd-networkd.service(8)
    ConditionCapability=CAP_NET_ADMIN
    DefaultDependencies=no
    # systemd-udevd.service can be dropped once tuntap is moved to netlink
    After=systemd-networkd.socket systemd-udevd.service network-pre.target systemd-sysusers.service systemd-sysctl.service
    Before=network.target multi-user.target shutdown.target
    Conflicts=shutdown.target
    Wants=systemd-networkd.socket network.target
    [Service]
    AmbientCapabilities=CAP_NET_ADMIN CAP_NET_BIND_SERVICE CAP_NET_BROADCAST CAP_NET_RAW
    BusName=org.freedesktop.network1
    CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE CAP_NET_BROADCAST CAP_NET_RAW
    DeviceAllow=char-* rw
    ExecStart=!!/lib/systemd/systemd-networkd
    LockPersonality=yes
    MemoryDenyWriteExecute=yes
    NoNewPrivileges=yes
    ProtectProc=invisible
    ProtectClock=yes
    ProtectControlGroups=yes
    ProtectHome=yes
    ProtectKernelLogs=yes
    ProtectKernelModules=yes
    ProtectSystem=strict
    Restart=on-failure
    RestartKillSignal=SIGUSR2
    RestartSec=0
    RestrictAddressFamilies=AF_UNIX AF_NETLINK AF_INET AF_INET6 AF_PACKET AF_ALG
    RestrictNamespaces=yes
    RestrictRealtime=yes
    RestrictSUIDSGID=yes
    RuntimeDirectory=systemd/netif
    RuntimeDirectoryPreserve=yes
    SystemCallArchitectures=native
    SystemCallErrorNumber=EPERM
    SystemCallFilter=@system-service
    Type=notify
    User=systemd-network
    WatchdogSec=3min
    
    [Install]
    WantedBy=multi-user.target
    Also=systemd-networkd.socket
    Alias=dbus-org.freedesktop.network1.service
    
    # We want to enable systemd-networkd-wait-online.service whenever this service
    # is enabled. systemd-networkd-wait-online.service has
    # WantedBy=network-online.target, so enabling it only has an effect if
    # network-online.target itself is enabled or pulled in by some other unit.
    Also=systemd-networkd-wait-online.service
    

    SEE

    systemd(1), systemd-timesyncd.service(8), systemd-networkd.service(8)


    timedate.conf

    /usr/share/dbus-1/system.d/org.freedesktop.timedate1.conf
     <busconfig> 
            <policy user="root">
                    <allow own="org.freedesktop.timedate1">
                    <allow send_destination="org.freedesktop.timedate1">
                    <allow receive_sender  ="org.freedesktop.timedate1">
            </policy> 
            <policy context="default">
                    <allow send_destination="org.freedesktop.timedate1">
                    <allow receive_sender  ="org.freedesktop.timedate1">
            </policy> 
    </busconfig></pre>