Configure the time zone (TZ) on Linux systems

Having the right time set on a Linux system is important for data synchronization, forensics, and troubleshooting. Next step is to configure the correct time zone. This article will help you:

  • See the current time configuration
  • Learn how to configure the time zone

Time zone information

We will have a look on how to check and configure the time zone on Linux systems.

Show current time zone

Most new Linux distributions use systemd now. With the timedatectl command we can quickly see the existing time information, including the time zone.

timedatectl

The timedatectl output might be something like this.

See Linux time zone configuration with timedatectl

Now systemd uses a combination of its own configuration files and the well-known ones. For Linux systems, there are typically two files related to the configuration of time zone information.

  • /etc/localtime
  • /etc/timezone

The differences between localtime and timezone are their format and type of content. Let’s start with localtime.

The file /etc/localtime is usually is a symbolic link to another file. With the readlink command we can see the related time zone.

readlink /etc/localtime

The output on a system in The Netherlands would be looking like this:

Time zone configuration via /etc/localtime

For systems that use systemd, the localtime file also used.

The /etc/timezone file is a plain text file. It usually includes the continent and place, unless a more generic setting is used like UTC.

cat /etc/timezone

Our system would show “Europe/Amsterdam”, which is the same value as the localtime file.

Time zone configuration

There are a few ways to configure the time zone on Linux distributions. Here are some of the options:

Using timedatectl (systemd)

The first option is for all Linux distributions that use systemd. There should be a timedatectl command available and allows you to make the changes.

timedatectl set-timezone Europe/Amsterdam

If you have multiple systems in different time zones, then UTC would be the best zone to use. This way all systems use the same information.

timedatectl set-timezone UTC

Using tzselect

Linux time zone configuration with tzselect utility

Using dpkg-reconfigure (Debian/Ubuntu)

Systems that are running Debian, Ubuntu, or similar, can use the dpkg-reconfigure tool. An interactive menu will guide you through the configuration.

dpkg-reconfigure tzdata

Time zone and scripts

The variable TZ is not exported by default on some Linux distributions. You can easily check this by using the export command.

If your Linux distribution has a /etc/profile.d directory, then most likely this is the best place to set the time zone. This way all users get the same value when they log in.

Configure the Linux time zone via a system-wide setting

After logging in, each user will now have this time zone as the default value. This is actually only the best solution is all users on the systems are actually in the same time zone. Otherwise, you better have users override it via their local ~/.profile (home directory).

Found another way to set the configuration on your system? Let it know.

Relevant commands in this article

Like to learn more about the commands that were used in this article? Have a look, for some there is also a cheat sheet available.

  • readlink
  • timedatectl
  • tzselect

Feedback

Small picture of Michael Boelen

This article has been written by our Linux security expert Michael Boelen. With focus on creating high-quality articles and relevant examples, he wants to improve the field of Linux security. No more web full of copy-pasted blog posts.

Discovered outdated information or have a question? Share your thoughts. Thanks for your contribution!

Mastodon icon