16

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?

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

2 Answers 2

21

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)

2
  • In my case, date gives a different time-zose and time than uname -a. Why would that be?
    – Geremia
    Jul 8, 2017 at 22:16
  • 1
    uname doesn't list the current timezone or anything regarding time. If you run uname -v, that will print the version of the kernel currently running which might include a timestamp listing when the kernel was built. That's a static piece of text that is not affected by your TZ setting.
    – JM0
    Mar 25, 2021 at 18:47
9

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.

2
  • 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. Mar 3, 2014 at 9:33
  • 1
    Friendly reminder. Remember to restart sshd for changes to take effect. On ubuntu "service ssh restart"
    – cavalcade
    Feb 22, 2015 at 5:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .