time zone
Linux

How to Set or Change the Time Zone in Linux

Time zone is a geographic region where all the clocks are set to the same time. generally during an OS, it is requested to set time zone. In this article we will see how to change it on Linux OS.

Why a correct time zones is important

time zone
time zone

Using the correct time zone on Linux is essential because it ensures that your system’s clock is accurate and synchronized with the correct time.

If your system’s clock is set to the wrong time zone, it can cause a range of problems, including :

Incorrect timestamps :

If you create or modify files, log data, or perform other actions on your system, the timestamps associated with these actions will be incorrect if your system’s clock is set to the wrong time zone. This can make it difficult to troubleshoot issues and can cause confusion if you need to collaborate with others.

Incorrect scheduling :

If your system is configured to perform tasks at specific times (cron, backups, updates), these tasks may be triggered at the wrong time if your system’s clock is set to the wrong time zone.

Security issues :

Some security mechanisms, such as SSL certificates, rely on accurate timekeeping to function correctly. If your system’s clock is set to the wrong time zone, it may be unable to validate SSL certificates correctly, which can leave your system vulnerable to attacks.

Checking the Current Time zone

To view the current time zone run timedatectl command :

[root@sysreseau ~]# timedatectl
      Local time: Fri 2023-03-03 09:35:12 EST
  Universal time: Fri 2023-03-03 14:35:12 UTC
        RTC time: Fri 2023-03-03 14:35:10
       Time zone: America/New_York (EST, -0500)
     NTP enabled: yes
NTP synchronized: no
 RTC in local TZ: no
      DST active: no
 Last DST change: DST ended at
                  Sun 2022-11-06 01:59:59 EDT
                  Sun 2022-11-06 01:00:00 EST
 Next DST change: DST begins (the clock jumps one hour forward) at
                  Sun 2023-03-12 01:59:59 EST
                  Sun 2023-03-12 03:00:00 EDT

As you can see, the output above shows that the system’s time zone is set to America/New_York.

You can also check the time zone by running the commande bellow :

[root@sysreseau ~]# ls -l /etc/localtime
lrwxrwxrwx. 1 root root 38 Feb  8  2022 /etc/localtime -> ../usr/share/zoneinfo/America/New_York

Changing the Time Zone in Linux

To change the time we will use timedatectl again. But before that, to view all available time zones, run the commande bellow :

[root@ple32spacewalk ~]# timedatectl list-timezones
Africa/Abidjan
Africa/Accra
Africa/Addis_Ababa
Africa/Algiers
Africa/Asmara
Africa/Bamako
Africa/Bangui
Africa/Banjul
Africa/Bissau
Africa/Blantyre
Africa/Brazzaville
Africa/Bujumbura

...
...
...
Pacific/Port_Moresby
Pacific/Rarotonga
Pacific/Saipan
Pacific/Tahiti
Pacific/Tarawa
Pacific/Tongatapu
Pacific/Wake
Pacific/Wallis
UTC

For exemple to change the system’s time zone to « America/Los_Angeles » run the following command :

# timedatectl set-timezone America/Los_Angeles

The verify the Current time zone with timedatectl command :

[root@sysreseau ~]# timedatectl
      Local time: Fri 2023-03-03 09:35:12 EST
  Universal time: Fri 2023-03-03 14:35:12 UTC
        RTC time: Fri 2023-03-03 14:35:10
       Time zone: America/Los_Angeles (EST, -0500)
     NTP enabled: yes
NTP synchronized: no
 RTC in local TZ: no
      DST active: no
 Last DST change: DST ended at
                  Sun 2022-11-06 01:59:59 EDT
                  Sun 2022-11-06 01:00:00 EST
 Next DST change: DST begins (the clock jumps one hour forward) at
                  Sun 2023-03-12 01:59:59 EST
                  Sun 2023-03-12 03:00:00 EDT

You might also like

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *