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

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 in the comments.

One more thing...

Keep learning

So you are interested in Linux security? Join the Linux Security Expert training program, a practical and lab-based training ground. For those who want to become (or stay) a Linux security expert.

See training package




Lynis Enterprise screenshot to help with system hardeningSecurity scanning with Lynis and Lynis Enterprise

Run automated security scans and increase your defenses. Lynis is an open source security tool to perform in-depth audits. It helps with system hardening, vulnerability discovery, and compliance.


Download

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.