Virtual Private Server (VPS) configuration can either be really complex or at times be really simple such as the changing timezone. As simple it may be, it is vital to have the correct timezone set such as having proper logging in any IT transactional system. The three factors that will be affected by having an improper timezone in a Linux VPS server are loggings, automation and, cron jobs.
Setting the timezone improperly will affect the time of your application deployment. Aside from that, if it uses a NTP, it could be worse by having similar problems in various nodes of the network. There are multiple ways of changing the timezone, including using tools to automate it. In this article, the 2 methods we will be using to change the timezones are tzselect and timedatectl. The Linux distribution used in this guide is based on the Ubuntu operating system.
The tzselect command is available to all Debian-based distributions such as Ubuntu, Linux Mint, and Elementary OS. This command allows the change of timezone using a command-line interface. Firstly, access your VPS via SSH. Open your terminal by searching it through the application menu or by right-clicking the desktop and selecting the “Open Terminal” option, then run the following command in the terminal.
After running the command, a list of geographical areas will be shown in the output. Select any region of your needs and you should be able to see the list of timezones available in the selected region. Enter the index number of the region and timezone that you need and you should be done setting your timezone. After setting the timezone, it is safer to verify at least once if the timezone is similar to the one you had set using the following command.
With this, you have successfully changed your timezone with tzselect command.
Moving on to the next method of changing timezone using timedatectl command. This is a more detailed version of changing timezone compared to the method earlier. Firstly, similarly to tzselect, look for the available timezones. You are able to list the timezones using the following command.
A long list of timezones available will appear and it may be hard for the user to pick a proper one, press Ctrl+C to exit the display. To filter out the long list, use the grep command along with the command above to filter the name of the city in which timezone you need, such as the following command.
timedatectl list-timezones | grep <city_name>
Replace the “<city_name>” with the city which timezone you need the most to filter the long list. After learning which timezone you needed. use the following command to set the timezone on your system.
sudo timedatectl set-timezone <timezone>
Replace the “<timezone>” with the timezone you had selected and run the command. The system’s timezone should be set with this. To verify if it had already been set, use the following command.
You should be able to change the timezone of your system.