Configure the time zone (TZ) on Linux systems
Linux Time Zone Configuration
Having the right time set on a Linux system is important for the synchronization of data, forensics, and troubleshooting. Having the right time zone is the next step. We will have a look on how to check and configure the time zone on Linux systems.
See current time zone
Most new Linux distributions use systemd now. By using the timedatectl command we can quickly see the existing time information, including the time zone.
For Linux, there are typically two files related to the configuration of time zone information:
The file /etc/localtime is a binary file and is usually is a symbolic link. This file is also used by systemd. use the readlink command to see the related time zone.
The output on a system in The Netherlands would be looking like this:
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.
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 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.
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 time zone when they log in. This is only the best solution is all users on the systems are actually in the same time zone.
After logging in, each user will now have this time zone as the default value. They can still override it via their local ~/.profile (home directory).
Found another way to set the configuration on your system? Let it know in the comments.