Setting the time using Terminal

Setting the time using Terminal

From Debian Wiki

Jump to: navigation, search

Introduction

This is really basic stuff but if you aren't running a GUI then it isn't as easy as opening up a Time & Date Settings control panel so this is the way to do it.

Setting the timezone

You first want to check what the current date and time is on your machine. Do this by running the following in a Linux shell:

date

This should return something like this:

Tue Mar  6 20:47:59 SAST 2007

You can also check the timezone you're currently using by running:

cat /etc/timezone

Which would return something like this:

Africa/Johannesburg

Now if none of this is correct you want to setup your timezone by running this command:

tzconfig

On Debian Lenny (5.0) you need to run this command:

dpkg-reconfigure tzdata

Select your continent and type in your city and hit enter. This should return the following:

Your default time zone is set to 'Africa/Johannesburg'.
Local time is now:      Tue Mar  6 20:50:15 SAST 2007.
Universal Time is now:  Tue Mar  6 18:50:15 UTC 2007.

Synchronise your clock with a NTP server

NTP, the Network Time Protocol, is used to keep computer clocks accurate over the Internet. ntpdate is a simple NTP client which allows a system’s clock to be set to match the time obtained by communicating with one or more servers.

Install the ntp client

apt-get update
apt-get install ntpdate

ntpdate will automatically run when booting your system.