linuxenabled.com

Learn How to Set Time, Timezone and Sync Server Clock in Linux

Introduction

In this tutorial, you’ll learn how to configure the system time, set the correct timezone, and synchronize your Linux system clock with NTP using timedatectl, systemd-timesyncd, and chrony.

The timedatectl command is available on both RHEL-based and Debian-based distributions. It is part of the systemd system and service manager and replaces the traditional date command used in older sysvinit-based Linux systems. With timedatectl, you can view and modify system clock settings. This includes setting or changing the current date, time, and timezone, as well as enabling automatic time synchronization with a remote NTP server.

In this tutorial, you’ll be guided through managing time on a Linux system from the terminal—covering how to set the date, time, and timezone, and how to synchronize the system clock with NTP using timedatectl, systemd-timesyncd, and chrony. Maintaining accurate time on a Linux server or system is a best practice and offers several key benefits:

  • Ensures timely execution of system tasks, many of which are time-dependent. 
  • Provides accurate timestamps for logs and system events. Enables proper synchronization across distributed systems and applications.
  • Supports security mechanisms such as Kerberos authentication and SSL/TLS certificate validation

Finding and setting the local timezone in Linux

To check the current date and time on your Linux system, run the following command from the terminal:

 timedatectl status 

From the output, note that RTC time refers to the hardware clock time. System time in Linux is always interpreted based on the configured timezone. To view the currently set timezone, use either of the commands below:

 timedatectl 

Or filter the output to display only time-related information:

 timedatectl | grep Time 

To display a complete list of supported timezones on your system, run:

 timedatectl list-timezones 

You can narrow down the timezone list by region using egrep. For example:

 timedatectl list-timezones | egrep -o "Asia/B.*" 
 timedatectl list-timezones | egrep -o "Europe/L.*" 
 timedatectl list-timezones | egrep -o "America/N.*" 

This makes it easier to identify the correct timezone for your location. To configure your system’s timezone, use the set-timezone option as shown below:

 sudo timedatectl set-timezone "Asia/Kolkata" 

Verify the change with:

 timedatectl status 

It is generally recommended to configure servers to use Coordinated Universal Time (UTC). To do so, run:

 sudo timedatectl set-timezone UTC 

Then confirm the setting:

 timedatectl status 

⚠️ Make sure to specify a valid timezone name. If an incorrect timezone is provided, you will encounter an error similar to the following:

 failed to set time zone: invalid timezone 

Finding and setting the local time in Linux

To change only the system time, use the set-time option with the HH:MM:SS format (Hour:Minute:Second):

 sudo timedatectl set-time 12:25:30 

Verify the change by running:

 timedatectl status 

You may encounter the following error when attempting to set the time manually:

 Failed to set time: Automatic time synchronization is enabled 

This happens because automatic time synchronization (NTP) is enabled, which prevents manual changes to the system clock. To resolve this issue, disable NTP first, then set the time again:

 sudo timedatectl set-ntp false sudo timedatectl set-time 12:25:30 

Confirm the updated time with:

 timedatectl status 

To configure both the date and time simultaneously, use the set-time option with the following format: Date: YYYY-MM-DD (Year-Month-Day). Time: HH:MM:SS (Hour:Minute:Second)

For Example:

 sudo timedatectl set-time '2026-01-23 12:25:30' 

Finding and setting the hardware clock in Linux

To configure your hardware clock (RTC) to use Coordinated Universal Time (UTC), you can use the set-local-rtc option with a boolean value. First, determine whether your hardware clock is currently set to the local timezone:

 timedatectl | grep local 

If needed, you can configure the hardware clock to use the local timezone by running:

 sudo timedatectl set-local-rtc 1 

To set the hardware clock to UTC, which is the recommended configuration for most Linux systems and servers, use the following command:

 sudo timedatectl set-local-rtc 0 

⚠️ Setting the RTC to local time is not recommended, as it can lead to issues with daylight saving time changes and cause time drift. To avoid these problems, it is best practice to keep the hardware clock set to UTC.

Synchronizing Linux System Clock with a Remote NTP Server

NTP (Network Time Protocol) is an internet protocol used to synchronize system clocks across computers on a network. The timedatectl utility allows you to automatically synchronize your Linux system clock with remote NTP servers, ensuring accurate and consistent timekeeping. Most modern Linux distributions rely on one of the following NTP synchronization methods:

1) systemd-timesyncd: A lightweight SNTP (Simple NTP) client built into systemd. It is suitable for desktops, laptops, and single-server environments.

2) chrony: A full-featured NTP implementation that can function as both a client and a server. It offers better accuracy and handles intermittent network connections more effectively.

To enable and start automatic time synchronization using systemd-timesyncd, run:

 sudo timedatectl set-ntp true 

To turn off automatic NTP synchronization, use:

 sudo timedatectl set-ntp false 

To verify the current synchronization state, run:

 timedatectl status 

If synchronization is active, you should see:

System clock synchronized: yes
NTP service: active

For servers or environments that require higher accuracy and reliability, chrony is the preferred solution. It is especially well-suited for:

  1. Systems that do not run continuously (laptops and desktops) 
  2. Servers requiring precise timekeeping
  3. Systems with unstable or intermittent network connections
  4. Clustered environments where time consistency is critical

To Install chrony using your distribution’s package manager:

Debian-based systems:

 sudo apt install chrony 

RHEL-based systems:

 sudo dnf install chrony 

Note: Installing chrony automatically disables systemd-timesyncd to prevent conflicts. After installation, enable and start the chrony service, then verify synchronization:

 sudo systemctl enable --now chronyd 
 timedatectl status 

To use your own NTP servers instead of the default ones, edit the chrony configuration file:

 sudo nano /etc/chrony/chrony.conf 

Or create a custom sources file:

 sudo nano /etc/chrony/sources.d/custom.sources 

Add your preferred NTP servers (available from the NTP Pool Project):

 pool 0.pool.ntp.org iburst pool 1.pool.ntp.org iburst pool 2.pool.ntp.org iburst 

Restart chrony to apply the changes:

 sudo systemctl restart chronyd 

Important Notes About NTP Synchronization

  1. Only one NTP implementation can run at a time—choose either systemd-timesyncd or chrony
  2. systemd-timesyncd is client-only and cannot serve time to other systems
  3. chrony can act as both an NTP client and an NTP server
  4. For production servers and critical infrastructure, chrony is strongly recommended
  5. NTP requires UDP port 123 to be open for outbound network access

Conclusion

Accurate timekeeping is a fundamental requirement for any Linux system, whether it’s a personal workstation or a production server. In this tutorial, you learned how to manage system time, configure the correct timezone, adjust the hardware clock, and synchronize your Linux system clock with remote NTP servers using timedatectl, systemd-timesyncd, and chrony.

You also explored the differences between lightweight NTP synchronization with systemd-timesyncd and the more robust, server-grade capabilities of chrony, along with best practices such as keeping the hardware clock set to UTC and avoiding multiple NTP services running at the same time.

By applying these techniques, you can ensure reliable task scheduling, accurate logging, proper operation of distributed systems, and secure authentication mechanisms across your Linux environment. Whether you’re managing a single machine or an entire fleet of servers, maintaining correct system time will help keep your systems stable, predictable, and secure.

Scroll to Top