5

On a Ubuntu 14.04 vps, my timezone is set to UTC/GMT.

root@Ubuntu:/# date 
Fri Mar 11 13:36:56 GMT 2016

root@Ubuntu:/# cat /etc/timezone 
Europe/London

root@Ubuntu:/# ls -l /etc/localtime 
lrwxrwxrwx 1 root root 33 Mar 11 13:20 /etc/localtime -> /usr/share/zoneinfo/Europe/London

However, my log files in /var/log are all 9 hrs ahead (Korea time?). E.g

root@Ubuntu:/# tail -3 /var/log/auth.log.1

Mar 11 22:27:05 Ubuntu sshd[18170]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=211.99.249.89 
Mar 11 22:27:07 Ubuntu sshd[18170]: Failed password for invalid user cstrike from 211.99.249.89 port 38066 ssh2
Mar 11 22:27:07 Ubuntu sshd[18170]: Connection closed by 211.99.249.89 [preauth]

This remains the case even after a service rsyslog restart and dpkg-reconfigure tzdata.

How do I get everything on the same timezone?

2 Answers 2

9

I suffered from the same problem and issued the commands dpkg-reconfigure tzdata and service rsyslog restart in succession on a 14.04 server. I then initiated an ssh connection whilst viewing auth.log with

tail -f /var/log/auth.log

Log messages from then on were correct, as may be seen in this snippet

Aug 16 09:02:40 myhost sshd[11913]: Accepted publickey ...
Aug 16 09:02:40 myhost sshd[11913]: pam_unix(sshd:session): opened ...
Aug 16 09:02:43 myhost sshd[11913]: pam_unix(sshd:session): closed ...
Aug 16 15:04:45 myhost sshd[12019]: Accepted publickey .... 
Aug 16 15:04:45 myhost sshd[12019]: pam_unix(sshd:session): opened ...
Aug 16 15:05:11 myhost sshd[12019]: pam_unix(sshd:session): closed ...

I see you did a tail of auth.log.1 (an older log file). Making the timezone changes does not modify an existing log file retroactively. Was that the problem perhaps?

2
  • 4
    service rsyslog restart save my day
    – Ninja
    Oct 10, 2017 at 3:19
  • after doing the above steps i still had to restart apache2 for the logs to go to the right timezone: systemctl restart apache2 Jun 20, 2019 at 0:28
0

(As I answered elsewhere) This command did it for me in Ubuntu 22.10:

$ sudo timedatectl set-timezone America/New_York

Time zone names:

$ timedatectl list-timezones | less

Confirm:

$ timedatectl
           Local time: Sat 2022-11-26 10:52:08 EST
       Universal time: Sat 2022-11-26 15:52:08 UTC
             RTC time: Sat 2022-11-26 15:52:08
            Time zone: America/New_York (EST, -0500)

Log files will not show the new timezone until you restart. sudo apache2ctl restart did it for the apache logs but to get all the logs (mysql, certbot, etc):

$ reboot

I try not to hate Oracle, I really try. But to get /var/log/mysql/error.log to use my timezone setting I had to take this additional step:

sudo nano /etc/mysql/mysql.conf.d/timestamps_system.cnf

and put MTK's solution there:

[mysqld]
log_timestamps = SYSTEM

You must log in to answer this question.

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