How To Change Timezone On Debian 9

This comprehensive Linux guide expects that you run the following commands as root user but if you decide to run the commands as a different user then ensure that the user has sudo access and that you precede each of the privileged commands with sudo

Sometimes selecting the right timezone becomes very important as some task are highly dependent on time usually such tasks which include logging. using timestamps. Since these timestamps are based on system time, it becomes important to have the correct time zone configuration.

The system’s timezone is set during the installation, but it can be easily changed at a later time . The following tutorial shows the procedure for setting or changing the timezone in a Debian 9 environment.

Check Current Timezone

Type in the following command which allows to display as well as change the current time and timezone

root@codesposts:~# timedatectl
                      Local time: Mon 2019-07-01 20:34:15 UTC
                  Universal time: Mon 2019-07-01 20:34:15 UTC
                        RTC time: Mon 2019-07-01 20:34:16
                       Time zone: Etc/UTC (PKT, +0000)
       System clock synchronized: yes
systemd-timesyncd.service active: yes
                 RTC in local TZ: no

As shown on the output below, the system’s timezone is set to “UTC”:

In Debian systems, the timezone is changed by simlinking the timezone directory /etc/timezone to a timezone identifier, which are located in /usr/share/zoneinfo directory.

Change Current Timezone

The timezone in debian systems follows the following format: Region/City

To list all the time zones that are stored in the timezones directory open terminal and typein the following commands

root@codesposts:~# 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
Africa/Cairo
Africa/Casablanca
Africa/Ceuta
Africa/Conakry
Africa/Dakar
Africa/Dar_es_Salaam
Africa/Djibouti
Africa/Douala
...

Find your desired timezone from the list and then type in the following command in terminal

timezone set-timezone My_Region/My_City

For Example, I want to set the timezone to Asia/Karachi, I would run the following command

timezone set-timezone Asia/Karachi

Verify the change by typing in timedatectl again

root@codesposts:~# timedatectl
                      Local time: Mon 2019-07-01 21:24:20 PKT
                  Universal time: Mon 2019-07-01 16:24:20 UTC
                        RTC time: Mon 2019-07-01 16:24:21
                       Time zone: Asia/Karachi (PKT, +0500)
       System clock synchronized: yes
systemd-timesyncd.service active: yes
                 RTC in local TZ: no

Older Versions Of Debian

Some older versions of debian do not have timedatectl command. In this case we need to symlink the systems directory to the timezone directory. This can be achieved by following commands

Step One: Deleting the current timezone file

rm -f /etc/localtime

Step Two: Create a symlink as shown

ln -s /usr/share/zoneinfo/My_Region/My_city /etc/localtime

For Example: In my case it is Asia/Karachi, so the symlink would be

ln -s /usr/share/zoneinfo/Asia/Karachi /etc/localtime

Step Three: Verify the listing the directory contents of /etc/locatime file using the following command

root@codesposts:~# ls -l /etc/localtime
lrwxrwxrwx 1 root root 34 Jun 26 01:45 /etc/localtime -> ../usr/share/zoneinfo/Asia/Karachi

Alternatively you can also verify using the date command

root@codesposts:~# date
Mon Jul  1 21:26:15 PKT 2019

The post How To Change Timezone On Debian 9 appeared first on CODESPOSTS.COM.

Go to Source
Author: staff

Ubuntu Server Admin

Recent Posts

Ubuntu MATE 26.10 Release Notes

Lo and behold 👐, Ubuntu MATE 26.10 (Stonking Stingray) is here! 🎊 We are back…

1 month ago

How to Deploy Kiwix Server on Ubuntu VPS

This article provides a guide demonstrating how to deploy Kiwix Server on Ubuntu VPS. What…

1 month ago

How to Host a Discord Bot on Ubuntu VPS

This article provides a guide demonstrating how to host a Discord bot on Ubuntu VPS.…

1 month ago

Myna speech-to-text is now available as a technology preview

A few months ago, we introduced Myna, our project to bring private, local speech-to-text dictation…

1 month ago

What’s new in security for Ubuntu 26.10?

Ubuntu 26.10 “Stonking Stingray” arrives at a time when AI tools are accelerating vulnerability discovery.…

1 month ago

Devpack for Rust: Zero to Rust in seconds

One of the best things about Rust is how easy it is to get started.…

2 months ago