ObjectiveThe objective of this guide is to provide the reader with instructions on how to setup time synchronization on Ubuntu 18.04 Bionic Beaver Linux. In this short Ubuntu sync time guide we will show how to get the current time as well as enable, disable and test time sync on your system.
Operating System and Software Versions
- Operating System: - Ubuntu 18.04 Bionic Beaver
RequirementsPrivileged access to your Ubuntu System as root or via
sudocommand is required.
- # - requires given linux commands to be executed with root privileges either directly as a root user or by use of
- $ - requires given linux commands to be executed as a regular non-privileged user
Getting Current Date, Time and TimezoneTime synchronization is enabled on Ubuntu 18.04 by default using systemd's timesyncd service. Use
timedatectlto confirm that your system is set with time synchronization:
From the above
$ timedatectl Local time: Wed 2018-03-21 07:21:41 AEDT Universal time: Tue 2018-03-20 20:21:41 UTC RTC time: Tue 2018-03-20 20:21:42 Time zone: Australia/Sydney (AEDT, +1100) System clock synchronized: yes systemd-timesyncd.service active: yes RTC in local TZ: no
timedatectlcommand output on Line 6 we can see that the Ubuntu time sync is enabled. Furthermore, Line 5 we can also see the configured timezone.
Timezone settingsIn order to have an accurate time and time synchronization to work properly, the system has to be configured with the correct timezone. Set your correct timezone before proceeding further by following our How to change timezone on Ubuntu 18.04 tutorial.
Enable/Disable Time SynchronizationTo turn off your Ubuntu time sync enter:
$ sudo timedatectl set-ntp off $ timedatectl Local time: Wed 2018-03-21 07:44:53 AEDT Universal time: Tue 2018-03-20 20:44:53 UTC RTC time: Tue 2018-03-20 20:44:54 Time zone: Australia/Sydney (AEDT, +1100) System clock synchronized: yes systemd-timesyncd.service active: no RTC in local TZ: noIf your time synchronization is disabled, execute the following linux command to enable your Ubuntu time sync:
$ sudo timedatectl set-ntp onYour Ubuntu 18.04 system is now time synchronized.
Test Time Sync on UbuntuThe following linux commands will confirm that the time sync is set correctly.
First, use the
datecommand to check the current date and time:
$ date Wed 21 Mar 07:54:50 AEDT 2018Next, with time sync enabled set an incorrect time. For example the following linux command will set the time few minutes ahead:
$ sudo date 03210800 Wed 21 Mar 08:00:00 AEDT 2018If your time synchronization is enabled correctly the time will reset to the synced time:
$ date Wed 21 Mar 07:55:09 AEDT 2018Next, disable Ubuntu systemd's timesyncd service:
$ sudo timedatectl set-ntp offSet an incorrect time, check the date and re-enable time sync:
$ sudo date 03210800 Wed 21 Mar 08:00:00 AEDT 2018 $ date Wed 21 Mar 08:00:14 AEDT 2018 $ sudo timedatectl set-ntp on $ date Wed 21 Mar 07:55:45 AEDT 2018If your time has switched back after you had re-enabled time synchronization then your Ubuntu time sync is enabled correctly.