On servers timezone and tmux

A while ago I was fighting with a timezone set on a server because of the daylight saving time kicked in: during the ghost hour I had troubles with finding automated jobs. Moreover, the server was located overseas and depending on when I was checking the remote date and time, I could get a different time delta.

Then, the quasi-philosophical question about “which timezone should be set for a remote server: my timezone or local timezone to the server?” has began rolling in my mind.

After some research, I found a piece of technical advice from Yeller. In short, their advice can be summarized with:

Use UTC
Use UTC. Use UTC. Use UTC. Use UTC. Use UTC. Use UTC. Use UTC. Use UTC. Use UTC. Use UTC. Use UTC. Use UTC. Use UTC. Use UTC.

(no, really check the linked post: it is full of good and agreeable technical points to use UTC).

After setting the default timezone for all my servers to UTC, there are some tweaks to live happily ever after with UTC.

First, add your timezone and export it into the TZ variable:

echo 'export TZ=/usr/share/zoneinfo/Europe/Rome' >> ~/.zshrc

This brings a notable advantages:

  • without TZ set:

% date
Mon Mar 25 20:56:43 2019
journalctl -f
[...]
Mar 25 20:57:51 golf systemd-logind[1154]: Session 980 logged out. Waiting for processes to exit.

  • with TZ set you get every message* localized in the selected timezone:

% date
Mon Mar 25 21:57:53 CET 2019
journalctl -f
[...]
Mar 25 21:57:51 golf systemd-logind[1154]: Session 980 logged out. Waiting for processes to exit.

* = every message from a sane and decently written program that knows about timezones and honors the TZ variable.

Secondly, I usually have everything running in a tmux session with the time in the tab bar. After changing the server timezone to UTC, tmux was outputting the time in UTC: I wanted to show my local time as well. In order to show localized time, you have to change some parameters:

  • Output the time and the timezone in the tab bar:

In ~/.tmux.conf:
set -g status-right '%a %b %d %H:%M %Z'

  • Make sure to send your TZ variable whenever you are using SSH:

In ~/.ssh/config:
Host *
[...]
SendEnv TZ

  • Make sure that your SSH server automatically accepts the TZ variable:

In /etc/ssh/sshd_config
AcceptEnv [...] TZ

Restart your sshd service and try to login in the remote server. Your tmux tab bar should show the updated time in your localized timezone, while still using UTC as the global timezone for the server.

Leave a Reply