How to Sync Time on Linux System using Chrony

Accurate date and time is essential in Linux systems because some services such as job scheduler (cron jobs) and scripts rely on the accurate time to provide expected output. The network time protocol commonly known as NTP is used to maintain the accurate time in Linux systems. NTP is an internet protocol which plays a vital role in synchronizing the date and time in Linux systems from the available online NTP servers.

Most of the old Linux systems have been using ntpd daemon to synchronize the date and time but in some modern operating systems, it is deprecated. For the implementation of ntpd in modern OSes we have chrony. In this article we will learn how to install and use chrony on Linux system to synchronize date and time.

Installation of Chrony

Installation of chrony in Linux system is a very simple process. Run the following command to install chrony.

CentOS/RHEL

In the centOS and RHEL system, run the following command to install chrony.

$ sudo yum install chrony -y
Or
$ sudo dnf install chrony -y

Ubuntu/Debian

Use the following command to install chrony in ubuntu and debian system

$ sudo apt install chrony -y

OpenSUSE

$ sudo zypper -n install chrony

Chrony comes with two programs after its complete installation

  • chronyd : It is chrony daemon which enables and starts chrony service
  • chrony : It is a chrony command line interface.

Configuration file

Configuration file of chrony is located at the directory /etc/chrony as chrony.conf (Ubuntu/Debian) and /etc/ as chrony.conf (RHEL/CentOS)  The default configuration  file looks like below:

Chrony-conf-linux

Configuration parameters.

  • pool ntp.ubuntu.com  iburst  => This is the ntp server from which chrony synchronizes the time.
  • keyfile /etc/chrony/chrony.keys =>  The key file contains an ID/key pair which is used for NTP authentication.
  • driftfile /var/lib/chrony/chrony.drift  => Chronyd stores rate information in the drift file
  • logdir /var/log/chrony  => This is a log file for chronyd.

Testing chrony

Testing of chrony can be done by using remote NTP server to sync the time. You can use chrony command with option -q along with a remote NTP server. In this example, I have used remote ntp server 1.north-america.pool.ntp.org to fetch the time. You can select your NTP server accordingly.

$ sudo chronyd -q  'server 1.north-america.pool.ntp.org iburst'

The server option iburst can be used to speed up the initial synchronization. If an NTP server is unresponsive , the iburst mode continues to send continuous queries until the server responds and time synchronization starts.

Output:

Testing-Chrony-Linux

If there is any difference in the time, chrony will correct the system time.

Run the following command to start chrony service

$ sudo systemctl start chronyd

To start the chrony service at boot time, run the following command.

$ sudo systemctl enable chronyd

Monitor time synchronization

Once the chrony is started, we can monitor the activity by running the following command

$ chronyc activity

Output :

chrony-activity-linux

To find a detailed list of NTP servers run the following command:

$ chronyc sources

Chrony-Sources-Linux

Parameters explained:

  • ^ Servers
  • + other acceptable NTP sources
  • * Indicates the NTP server from which chronyd is fetching time
  • ? Indicates the NTP source to which connection is lost

To get the more details about the NTP sources, you can run chronyc command with option -v for verbose output.

$ chronyc sources -v

Chrony-Sources-Verbose-Linux

To verify if the chrony is synchronizing the time in your system, run the following command.

$ chronyc tracking

Chrony-track-linux

Output explained :

  • Reference ID: The ID and name of the remote NTP server
  • Stratum : It show how many hops away from the computer with an attached reference clock
  • Last offset : Estimated local offset on the last clock update
  • Frequency : It shows the rate by which the system’s clock would be wrong if chrony was not correcting it.
  • Skew: It shows the estimated error bound on the frequency.

Conclusion

In this article, you have learned how to install  and use chrony on Linux system to sync time. If you have any feedback and suggestions, kindly drop your comment below.

Recommended Read: 14 Useful AWK Command Examples in Linux

Leave a Comment

5 × one =