Update Server Time/Date from Linux Command Line (SSH)
Quite often, you’ll notice the time stamp (and maybe even the dates tamp) incorrect on entries in the log which can sometimes prove a frustrating experience trying to identify when exactly various errors occurred.
From the Linux command line, you can check the server time/date with date
to confirm what the server things the current time/date is. And usually, you’ll be able to modify this with:-
date --set="STRING"
So, for example, if you wanted to update the date to 10/10/2014 15:09, you would use:-
date --set="10 OCT 2014 15:09:00"
But sometimes, you won’t be permitted to change the date (often with VPS’s) and you’ll receive the following error:-
date: cannot set date: Operation not permitted
What you can do instead (with root privileges), is remove the existing localtime
and then recreate the symbolic link for the timezone.
Say for example, you want to set it to Greenwich Meantime, you could carry out the following:-
rm /etc/localtime ln -s /usr/share/zoneinfo/GMT /etc/localtime
Or if the clocks have gone forward (UK) and you find setting it to GMT sets the time an hour in front, you can set it to Europe/London:-
rm /etc/localtime ln -s /usr/share/zoneinfo/Europe/London /etc/localtime
Listed below are the symbolic links you would need to create the for each country:-
United Kingdom
ln -s /usr/share/zoneinfo/GMT /etc/localtime
ln -s /usr/share/zoneinfo/Europe/London /etc/localtime
United States
ln -s /usr/share/zoneinfo/EST /etc/localtime
ln -s /usr/share/zoneinfo/US/Alaska /etc/localtime
ln -s /usr/share/zoneinfo/US/Aleutian /etc/localtime
ln -s /usr/share/zoneinfo/US/Arizona /etc/localtime
ln -s /usr/share/zoneinfo/US/Central /etc/localtime
ln -s /usr/share/zoneinfo/US/Eastern /etc/localtime
ln -s /usr/share/zoneinfo/US/East-Indiana /etc/localtime
ln -s /usr/share/zoneinfo/US/Hawaii /etc/localtime
ln -s /usr/share/zoneinfo/US/Indiana-Starke /etc/localtime
ln -s /usr/share/zoneinfo/US/Michigan /etc/localtime
ln -s /usr/share/zoneinfo/US/Mountain /etc/localtime
ln -s /usr/share/zoneinfo/US/Pacific /etc/localtime
ln -s /usr/share/zoneinfo/US/Pacific-New /etc/localtime
ln -s /usr/share/zoneinfo/US/Samoa /etc/localtime