Setting the correct date, time, time zone and synchronization are the first basic steps that you should perform when provisioning your Ubuntu 22.04 server for the first time.
An accurate time on your Linux machine ensures the smooth operation of your server. For instance, if you have some cron jobs, they need to run accurately on the specified timing. Also, the correct date makes sure that logs are recorded in the right order on your machine.
Some applications also rely on the system date to check for updates. So, if your system date/time goes out of sync, your server will be prone to errors and a lot of hard-to-resolve issues.
Time synchronization is enabled by default on Ubuntu 22.04 but it is good to double check that everything is working as expected. Also, you need to change the time zone per your requirement.
The purpose of this guide is to show you how to check, enable and disable date/time synchronization on your Ubuntu 22.04 server.
Pre-requisites
- A Linux server running Ubuntu 22.04 LTS Jammy Jellyfish
- A non-root user with sudo privileges
Step 1: Checking your local Ubuntu 22.04 time settings
You can check your Ubuntu 22.04 server local time, time zone and synchronization status by typing the command below on a terminal window. You don’t require to prefix the command with sudo:
$ timedatectl
The command above will output the information below:
As you can see from the above screen, the server’s Time zone is CDT and the “system clock synchronized” status is already set to “yes”
Step 2: Checking the list of available time zones on Ubuntu 22.04 server
In order for date/time synchronization to work well on your Ubuntu 22.04 server, you need to set the proper time zone.
First, check the available time zones on your Ubuntu 22.04 server by running the command below:
$ timedatectl list-timezones
The command will display all available time zones on your server. This is a very long list. However, you can use the grep command to limit the list to a specific area.
For instance to see a list of all America time zones, type the command below:
$ timedatectl list-timezones | grep -i america
Output
With a narrowed list like the one shown above, you can choose the right time zone for your server.
Step 3: Changing the time zone on Ubuntu 22.04 server
Changing the time zone is very simple on Ubuntu 22.04 server. For instance,to change our server’s time zone to “America/New_York” from our list above, we will use the command below:
$ sudo timedatectl set-timezone America/New_York
We can run the timedatectl command to ensure that the changes were effected successfully.
Output
Step 4: Enabling/Disabling time synchronization
Ubuntu 22.04 utilizes the NTP (Network Time Protocol) server daemon, which connects to a pool of Network Time Protocol servers to get constant and accurate time updates.
From the image above, we can see the NTP service status is already set to “active”. However, you can activate it on your system by running the command below:
$ sudo timedatectl set-ntp on
You can deactivate the NTP service by typing the command below
$ sudo timedatectl set-ntp off
To confirm the changes, run the timedatectl command.
Output
Conclusion
In this guide, we showed you the view of your system date, time and list all the available time zones. We have also taken you through the steps of changing your Ubuntu 22.04 server time zone as well as enabling/disabling time synchronization on the NTP server daemon. With the above information, you will be able to run your VPS without any problems when it comes to accurate date and time on your server.