How to Set Up Time Synchronization on Debian

August 9, 2023

Introduction

Time synchronization is essential for ensuring the reliability, security, and functionality of Debian and other Unix-like systems. The Network Time Protocol (NTP) is an essential element for time sync that synchronizes the clocks of client computers with a time server.

This article explains how to set up time synchronization on Debian using NTP and an alternative.

Set up time synchronization on Debian

Prerequisites

  • Debian system (this tutorial uses Debian 11).
  • Non-root sudo access.

Setting up Time Sync on Debian

Correct time setting is essential for the proper functioning of modern software. Poor time synchronization across systems leads to various issues, from simple errors to severe data corruption. The following sections explain how to set up time synchronization on Debian.

Step 1: Check Time on Debian

Check the time on the server with the date command:

date
date terminal output

The output shows the current time as well as the current date. The current time in the output is usually in Coordinated Universal Time (UTC). UTC is the time at zero degrees longitude and is accepted as a universal timezone.

Step 2: Set up Timezone

The date command prints the UTC zone by default. However, users sometimes need to change the timezone on Debian, which is done with the timedatectl command. Take the following steps to change the timezone on Debian:

1. List the available timezones on Debian:

timedatectl list-timezones
Listing timezones in Debian.

The command prints a list of all the available timezones. 

2. Navigate the output with the Spacebar and b key. 

3. Choose the timezone. For example, US/Eastern.

Choosing a US/Eastern timezone.

4. Press q to exit the list.

5. Change the timezone with the following command:

sudo timedatectl set-timezone <timezone>

For example, to change the timezone to US/Eastern run:

sudo timedatectl set-timezone US/Eastern

The command shows no output

6. Verify the change with date:

date
Changing the timezone.

The output shows the EDT time, the abbreviation for Eastern Daylight Time in US and Canada. 

Step 3: Check The Status of ntpd

Debian runs the standard Network Time Protocol daemon (ntpd) to sync the system time with external time servers. While NTP is the protocol for synchronizing time, ntpd is the program which implements the NTP protocol.

To confirm ntpd is running, execute the systemctl command:

sudo systemctl status ntp
Output for sudo systemctl status ntp

The output shows the ntpd service is active. Therefore, ntpd is running and in sync with a time server.

However, the ntpq command provides additional info about the ntpd status:

ntpq -p
Output for ntpg -p

The ntpq command is an ntpd query tool. The -p argument specifies info about the NTP servers to which ntpd currently connects to.

Switching from ntpd to timesyncd

Timesyncd is a lightweight ntpd alternative, which is simpler to configure, more efficient, and more secure. Furthermore, timesyncd also integrates better with systemd. This feature makes it easy to manage using the systemd commands.

However, timesyncd cannot be used as a time server, and it is less sophisticated in keeping the system time in sync. These features make the program a less suitable choice for systems in need of accuracy and reliability. Complex real-time distributed systems generally work better with ntpd.

Still, users who choose timesyncd need to remove ntpd first. Follow the steps:

1. Uninstall ntpd:

sudo apt purge ntp
Output for sudo apt purge

2. If the timesyncd is not on the system, run the following to install it:

sudo apt install systemd-timesyncd
Terminal output for sudo apt install systemd timesyncd

2. Start the timesyncd service:

sudo systemctl start systemd-timesyncd

The command has no output.

3. Check the status:

sudo systemctl status systemd-timesyncd
Output for sudo systemctl status systemd-timesyncd

The output confirms timesyncd is running. To display the current time and date, run:

timedatectl
Output for timedatectl

The output prints info such as:

  • Local time.
  • Universal time.
  • System real-time clock (RTC) time.
  • Timezone.
  • Confirmation the system clock is synchronized.

Note: Using ntpd instead of timesyncd does not change the process of checking the date and time, or timezones, or changing timezones. The commands are the same, regardless of which NTP daemon is used.

Conclusion

After reading this text, you now know how to set up time synchronization on Debian with ntpd and timesyncd.

Next, learn how to get the current date and time in Python or how to use JavaScript to get the current date and time.

Was this article helpful?
YesNo
Sara Zivanov
Sara Zivanov is a technical writer at phoenixNAP who is passionate about making high-tech concepts accessible to everyone. Her experience as a content writer and her background in Engineering and Project Management allows her to streamline complex processes and make them user-friendly through her content.
Next you should read
How to Generate & Set Up SSH Keys on Debian
September 14, 2020

This article will help system administrators configure SSH Keys on Debian 10. The instructions allow you to set up encrypted credentials quickly, log in remotely, and disable authentication...
Read more
How to Change Hostname in Debian
August 11, 2021

You can change the hostname in Debian 10 (Buster) as the root user by using the built-in hostname command or editing related system files. learn how to change your hostname in this step-by-step tutorial...
Read more
Server Operating Systems: Server OS Types & How to Choose
March 10, 2022

A server operating system is software designed to power a server computer. Learn more about server operating systems and read tips on choosing the best server OS for your...
Read more
How to Get the Current Date in Python
July 23, 2024

The article shows you how to create a basic Python script that displays the current date and time. Find out how to use the strftime() method and the datetime module to format the information you need...
Read more