Change Linux server timezone by ssh

To change the Linux timezone, you must first be well acquainted with the Linux commands. In the Linux Commands tutorial article, we have fully explained how to use the Linux commands.

There are several ways to change the Linux timezone, we will try to show you the best methods in this tutorial, stay tuned.

To view the date and time of Linux, you can use the date command in the ssh environment.

In many cases, after installing Linux , the location chosen by default is a different country from where you live, which will make it difficult for you in the future to check for logs, CMS history, and transaction timing of your website.

So we recommend that after installing your Linux, the first thing you do is set up and change your Linux timezone .

A surefire way to change your server time zone is to find information about your server geolocation in the etc / localtime / file.

So the first thing to know is the path of the file setting the time and date of your server, now you have to set the timezone of the server with its original backup file. The localtime file is actually a symbol link to the original file, which we will recount below.

The main directory of all geographical information and their time of occurrence is in the following path.

/ usr / share / zoneinfo /

zoneinfo- change timezone Linux

By going in this direction, you must select your country, to select Iran and the city of Tehran, you must follow the file below.

/ usr / share / zoneinfo / Asia / Tehran

Now you need to delete the current timezone file of your server with the following command.

rm -rf / etc / localtime

Then, with the following command, we enter the correct path to change the timezone of our Linux server.

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

Well, now you have to make the appropriate adjustment for your server hardware or personal system to keep up with changes in server performance such as reboot or shutdown of the server.

Nano / etc / sysconfig / clock

Now enter the following values ​​in the relevant file and save the changes.

ZONE = "Asia / Tehran"
UTC = false
ARC = false

Finally, save the changes to the hardware by entering the following command.

hwclock --systohc --localtime

Enter the hwclock command to make sure the Linux server timezone changes correctly.

In some cases, it is necessary to manually set the server clock once after changing the timezone. To do this, you can use the date command with the s-switch as shown below.

date -s '2017-12-25 12:34:56'

set time with date- Linux timezone change

Well, in the above command, we set both the date and the clock once to get the correct date from now on, because sometimes we noticed that this problem existed for some friends, so you can use this command.


Modify Linux timezone by ntp protocol

Another way to change the timezone is to use the ntp protocol. These servers run and work accurately and their time difference is very small. In this method, we move the server to the ntp connection protocol and the time received from the ntp servers will be done.

timedatectl set-time YYYY-MM-DD HH: MM: SS

With the above command we can set the date and time of the server, it is clear what the written symbols are for, but for those who are not aware, we will mention these items once.

HH: An hour
MM: A minute
SS: A second, all typed in two-digit form
YYYY: A four-digit year
MM: A two-digit month
DD: A two-digit day of the month
  • HH for two clock characters
  • MM for two minute characters
  • SS for two characters per second
  • YYYY for four characters of the year
  • MM for two moon characters
  • DD for two day characters

We can also not enter the date and time in numeric input format and apply it as a geographical timezone with the timedatectl command.

'timedatectl set-timezone' Asia / Tehran

Well, I hope you have been able to read and implement this tutorial to change your Linux server timezone properly so that you do not have problems in the future.

How useful was the training for you?

Leave a Reply

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