In this guide, we'll be showing you how to setup time synchronization on Ubuntu 20.04 Focal Fossa. Time synchronization is an important part of keeping your system clock up to date and configuring timezones correctly.In this tutorial you will learn:
- How to ascertain date and time information
- How to turn time synchronization on and off
- How to test time synchronization
- How to use GUI to edit time information
|Category||Requirements, Conventions or Software Version Used|
|System||Installed Ubuntu 20.04 or upgraded Ubuntu 20.04 Focal Fossa|
|Other||Privileged access to your Linux system as root or via the
# - requires given linux commands to be executed with root privileges either directly as a root user or by use of
Getting current time information
You can ascertain your system's current date, time, and timezone information with one command. You just need to open a terminal and type:
user1@linuxconfig:~$ timedatectl Local time: Wed 2020-03-11 22:06:50 -05 Universal time: Thu 2020-03-12 03:06:50 UTC RTC time: Thu 2020-03-12 03:06:51 Time zone: America/Lima (-05, -0500) System clock synchronized: yes NTP service: inactive RTC in local TZ: no
The output shows us the system's current timezone on Line 5 and confirms that the system clock is synchronized on Line 6.
Obviously, your system can only present you with the correct time if it has accurate information about what timezone you're in. If your system is not already configured with the correct timezone, check out our article on How to change timezone on Ubuntu 20.04 before proceeding further.
Enable or disable time synchronization
You can disable time synchronization on your system with the following command:
$ timedatectl set-ntp off
timedatectl command once more to confirm that time synchronization has been switched off:
user1@linuxconfig:~$ sudo timedatectl set-ntp off [sudo] password for user1: user1@linuxconfig:~$ timedatectl Local time: Wed 2020-03-11 22:23:25 -05 Universal time: Thu 2020-03-12 03:23:25 UTC RTC time: Thu 2020-03-12 03:23:26 Time zone: America/Lima (-05, -0500) System clock synchronized: no NTP service: inactive RTC in local TZ: no
To toggle time synchronization on, run the following command:
$ timedatectl set-ntp on
Your Ubuntu 20.04 system time should now be synchronized.
If executing the above command doesn't seem to have any effect on your system, you probably need to install the
ntp package. Run the following command to install it:
$ sudo apt install ntp
You'll need to restart your system before attempting to synchronize the time again.
Test time sync on Ubuntu
To confirm that your system has time synchronization setup correctly, we can do a little test with the
- First, use the
datecommand to check the current date and time:
user1@linuxconfig:~$ date Wed 11 Mar 2020 10:30:36 PM -05
- Next, while time sync is enabled, set an incorrect system time. For example, the following command will set our system time one day ahead at midnight:
$ user1@linuxconfig:~$ sudo date 03120000 Thu 12 Mar 2020 12:00:00 AM -05
- If your system has time synchronization configured correctly, the date and time will reset itself to the correct information:
user1@linuxconfig:~$ date Wed 11 Mar 2020 10:31:47 PM -05
- To see what happens when time synchronization is not configured, disable Ubuntu's timesyncd service with this command:
$ sudo timedatectl set-ntp off
- Now, set an incorrect time again. You should notice that the system no longer corrects the time automatically.
$ sudo date 03120000 Thu 12 Mar 2020 12:00:00 AM -05 $ date Thu 12 Mar 2020 12:00:08 AM -05 $ sudo timedatectl set-ntp on $ date Wed 11 Mar 2020 10:35:14 PM -05If the system clock has corrected itself after you re-enabled time synchronization, then your Ubuntu time sync is correctly configured.
Updating system time via GUI
You can also view and change your time settings via GUI in Ubuntu's settings. Open the settings from inside Ubuntu's application launcher.
In the settings menu, click on Date & Time in the navigation panel along the left side of the window. From here, you can configure the date, time, timezone, and synchronization settings.
In this article, we learned how to view and edit the date, time, and timezone information on Ubuntu 20.04 Focal Fossa. We also saw how to setup time synchronization to keep our system clock accurate at all times.
This guide also showed how to deploy the configuration by command line or GUI, and how to verify that the configuration was working as intended.