Home Terminal Tuts How to sync date and time from the command-line in Ubuntu

How to sync date and time from the command-line in Ubuntu

by Kiran Kumar
Published: Last Updated on
sync time command line ubuntu

Ubuntu uses NTP for synchronizing time over the internet. It is a TCP/IP protocol that fetches the current date and time from a server. The NTP servers are connected to atomic clocks via third-party servers.

Going a tad deeper, Ubuntu (16.04 onwards) uses timedatectl / timesyncd services to synchronize time. Optionally, one can use chrony to serve the Network Time Protocol.

Today, let’s learn the command lines used in the Terminal to get the date and time synced to the internet atomic clock.

If you ever learned this earlier, you might be remembering ntpdate. This is deprecated and replaced with a powerful timesyncd tool. By default settings, it regularly checks and keeps your computer’s local time in sync. It also stores time updates locally so that time is maintained even after the reboot.

Checking Current Status

Launch terminal and use the timedatectl command as follows:

timedatectl status

You should see the output similar to this one:

kiran@foss-linux:~$ timedatectl status
Local time: Mon 2018-08-13 21:54:25 EDT
Universal time: Tue 2018-08-14 01:54:25 UTC
RTC time: Tue 2018-08-14 01:54:25
Time zone: America/New_York (EDT, -0400)
System clock synchronized: yes
systemd-timesyncd.service active: yes
RTC in local TZ: no

Installing and using Chrony

To install Chrony, enter the following command in the Terminal:

sudo apt install chrony

If you require a one-shot sync use, use the following command in the Terminal.

chronyd -q

If you require a one-shot time check without setting the time, enter:

chronyd

Adding your own time servers

By default settings, Ubuntu fetches date and time from pool.ntp.org. You can view and edit the details. Use ‘Edit’ command in the ‘Terminal.’

Edit /etc/chrony/chrony.conf

By default, these servers are configured:

# Use servers from the NTP Pool Project. Approved by Ubuntu Technical Board
# on 2011-02-08 (LP: #104525). See http://www.pool.ntp.org/join.html for
# more information.
pool 0.ubuntu.pool.ntp.org iburst
pool 1.ubuntu.pool.ntp.org iburst
pool 2.ubuntu.pool.ntp.org iburst
pool 3.ubuntu.pool.ntp.org iburst

Go ahead and replace the server details as needed and then save the config file. Restart the chrony service for the new settings to take effect.

sudo systemctl restart chrony.service

That’s it! I hope you enjoyed learning the command line way of syncing the date and time of your Ubuntu PC.

You may also like

Leave a Comment

fl_logo_v3_footer

ENHANCE YOUR LINUX EXPERIENCE.



FOSS Linux is a leading resource for Linux enthusiasts and professionals alike. With a focus on providing the best Linux tutorials, open-source apps, news, and reviews written by team of expert authors. FOSS Linux is the go-to source for all things Linux.

Whether you’re a beginner or an experienced user, FOSS Linux has something for everyone.

Follow Us

Subscribe

©2016-2023 FOSS LINUX

A PART OF VIBRANT LEAF MEDIA COMPANY.

ALL RIGHTS RESERVED.

“Linux” is the registered trademark by Linus Torvalds in the U.S. and other countries.