Objective
The 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
Requirements
Privileged access to your Ubuntu System as root or via sudo
command is required.
Conventions
- # – requires given linux commands to be executed with root privileges either directly as a root user or by use of
sudo
command - $ – requires given linux commands to be executed as a regular non-privileged user
Other Versions of this Tutorial
Instructions
Getting Current Date, Time and Timezone
Time synchronization is enabled on Ubuntu 18.04 by default using systemd’s timesyncd service. Use timedatectl
to confirm that your system is set with time synchronization:
$ 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
From the above timedatectl
command 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 settings
In 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 Synchronization
To 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: no
If your time synchronization is disabled, execute the following linux command to enable your Ubuntu time sync:
$ sudo timedatectl set-ntp on
Your Ubuntu 18.04 system is now time synchronized.
Test Time Sync on Ubuntu
The following linux commands will confirm that the time sync is set correctly.
First, use the date
command to check the current date and time:
$ date Wed 21 Mar 07:54:50 AEDT 2018
Next, 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 2018
If your time synchronization is enabled correctly the time will reset to the synced time:
$ date Wed 21 Mar 07:55:09 AEDT 2018
Next, disable Ubuntu systemd’s timesyncd service:
$ sudo timedatectl set-ntp off
Set 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 2018
If your time has switched back after you had re-enabled time synchronization then your Ubuntu time sync is enabled correctly.