Setup timezone and update time from NTP

Having correct time on a server is very important. For example, you cannot join a Windows PC to a Domain if the time differs more than a few minutes (Five minutes if I'm not mistaking).

To setup time zone and update time from internet on Ubuntu Server, do the following:

Check timezone

$ date
Thu Mar 21 18:02:49 MST 2012

or check timezone file

$ more /etc/timezone
Europe/Zagreb

Setup timezone

sudo dpkg-reconfigure tzdata

and follow the instructions

Also, be sure to restart cron as it will not be aware of the change otherwise

$ /etc/init.d/cron stop
$ /etc/init.d/cron start

You can also update your time periodically by creating a daily crontab (crude but it works)

$ vim /etc/cron.daily/ntp

With the contents

#!/bin/sh
ntpdate zg1.ntp.carnet.hr zg2.ntp.carnet.hr

and make sure to make it executable

$ chmod 755 /etc/cron.daily/ntp