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 to be 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:

[email protected]:~$ 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, simply 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! Hope you enjoyed learning the command line way of syncing the date and time of your Ubuntu PC.

READ  How to find IP and MAC Address by command line in Linux
Previous articleHere’s the New Yaru Theme of Ubuntu 18.10, install it in Ubuntu 18.04 now!
Next articleHow to install Network Manager L2TP in Ubuntu
Hi there! I'm Kiran Kumar, founder of FOSSLinux.com. I'm an avid Linux lover and enjoy hands-on with new promising distros. Currently, I'm using Ubuntu as a daily driver and run several other distros such as Fedora, Solus, Manjaro, Debian, and some new ones on my test PC and virtual machines. I have a day job as an Engineer, and this website is one of my favorite past time activities especially during Winter ;). When I'm not writing for FOSSLinux, I'm seen biking and hiking on scenic trails. Hope you enjoy using this website as much as I do writing for it. Feedback from readers is something that inspires me to do more, and spread Linux love!. If you find a time, drop me an email or feedback from the 'Contact' page. Or simply leave a comment below if you found this article useful. Have a good day!

Leave a Reply

avatar
  Subscribe  
Notify of