11

I know that (for example in Debian) one could use dpkg-reconfigure tzdata to change the timezone of the system but I am wondering how one could change the user timezone (if Linux/Unix supports such an idea at all).

I normally work on the server remotely through ssh and given that the server works with UTC internally (files, ...) and timezones are rather superficial, I would like to see the times in my desired timezone depending on where I am connecting from. Is this possible?

  • What did you try? Did you even search for "ssh passing on TZ information" on the web at all? – Anthon Mar 3 '14 at 10:46
13

Use the TZ environment variable. E.g.:

bash$ export TZ=US/Pacific
bash$ date
Mon Mar  3 00:31:17 PST 2014
bash$ export TZ=US/Eastern
bash$ date
Mon Mar  3 03:33:06 EST 2014

The possible values for TZ are in the directory /usr/share/zoneinfo (see, for example, the existence of /usr/share/zoneinfo/US/Pacific)

  • In my case, date gives a different time-zose and time than uname -a. Why would that be? – Geremia Jul 8 '17 at 22:16
8

First, you need some configs for ssh server and ssh client.

In Server, in /etc/ssh/sshd_config, make sure you accept TZ variable:

AcceptEnv LANG LC_* TZ

In Client, in /etc/ssh/ssh_config or ~/.ssh/config, make sure you send TZ variable:

SendEnv TZ

(The defaults are usually to send none from the client, and accept none on the server.)

Then make alias for ssh command to use your current TZ in ssh session. Add this line to .bashrc file:

alias ssh='TZ=${TZ:-"$(cat /etc/timezone)"} ssh'

or use this for system doesn't have /etc/timezone:

alias ssh='TZ=${TZ:-"$(date +%Z)"} ssh'

Then every time you ssh to remote server, the time on server will display base on you local timezone.

  • You can also use TZ=$(date +%Z) with most versions (Linux/*BSD/Solaris) of date, this will work better on systems where /etc/timezone isn't the done thing. – mr.spuratic Mar 3 '14 at 9:33
  • Friendly reminder. Remember to restart sshd for changes to take effect. On ubuntu "service ssh restart" – cavalcade Feb 22 '15 at 5:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.