Linux Time Sync Setup: NTP & Chrony Guide

To configure automatic time updates on Linux, you can follow these steps:

  1. Open the terminal and log in with root privileges.
  2. Install the ntp service using the following command:
  3. Please install NTP using the sudo apt-get command.
  4. Or you can install the chrony service using the following command:
  5. install chrony using the sudo apt-get command
  6. You can use either of these two services to automatically update the time, just choose one to install.
  7. After the installation is completed, open the configuration file for configuration. For the NTP service, use the following command to edit the configuration file:
  8. Open the file ntp.conf in the /etc directory using the nano text editor with administrator privileges.
  9. To edit the configuration file for the chrony service, use the following command.
  10. Open the file chrony.conf in the directory /etc/chrony using the nano text editor with superuser privileges.
  11. In the configuration file, locate the setting for the time server, usually starting with ‘server’. One option is to use a public time server, such as:
  12. ntp server at aliyun.com
  13. Alternatively, you can use a local time server.
  14. Save the configuration file and exit.
  15. Start the ntp or chrony service, and initiate the ntp service with the following command:
  16. Start the NTP service with elevated privileges.
  17. Start the chrony service using the following command:
  18. Start the chrony service using sudo.
  19. Restart the service using the restart command if it is already running.
  20. Configure the system time synchronization method. For the NTP service, use the following command to configure the system time synchronization method:
  21. Execute the ntpdate command as a superuser with the server ntp.aliyun.com.
  22. No additional configuration is needed for the chrony service.

After completing the above steps, the system will automatically sync the time from the time server. You can manually sync the time using the following command:

sudo ntpdate ntp.aliyun.com

If you need to synchronize the time regularly, you can use the crontab task scheduler to set up scheduled tasks.

bannerAds