0

I am trying to set the system date on my linux machine. If it matters, it is an Amazon EC2 machine that I provisioned. I tried to set the date with this command:

sudo date -s "19 APR 2018 11:14:00";

However the date does not stay set for long; when I run the following:

sudo date -s "19 APR 2018 11:14:00"; date; date; date; date; date; date

I obtain:

Thu Apr 19 11:14:00 UTC 2018
Thu Apr 19 11:14:00 UTC 2018
Thu Apr 19 11:14:00 UTC 2018
Thu Apr 19 11:14:00 UTC 2018
Thu Apr 19 11:14:00 UTC 2018
Thu Apr 19 11:14:00 UTC 2018
Thu Oct 25 18:37:09 UTC 2018

Is there a background process resetting the date every second or so? What is going on here? How can I fix it?

Thanks in advance!

  • 4
    The system _is_ fixing it for you. You don't need to do anything. – Michael Hampton Oct 25 '18 at 18:50
  • 1
    (That system is likely to be something like `ntp` or `chrony`. You should note that disabling it to set an incorrect date may have side-effects; in my experience, for example, the AWS CodeDeploy agent fails if it sees more than about 15 minutes in time slip.) – ceejayoz Oct 25 '18 at 18:52
  • Possible duplicate of [centOs : system time getting reset back to UTC after changing it using timedatectl](https://serverfault.com/questions/935686/centos-system-time-getting-reset-back-to-utc-after-changing-it-using-timedatec) – kasperd Oct 25 '18 at 21:46
  • Hi Lorenzo, if the response below answered your question please upvote and accept it. That's the ServerFault's way to say thank you for the time and effort someone took to help you. Thanks! – MLu Nov 03 '18 at 04:00

3 Answers3

1

It's being corrected by chrony, at least on my Amazon Linux 2 instance. When I run your command I see this in the journalctl logs:

Oct 26 01:17:19 .. dhclient[2183]: XMT: Solicit on eth0, interval 115280ms.
Apr 19 11:14:00 .. systemd[1]: Time has been changed
Apr 19 11:15:10 .. chronyd[1853]: Backward time jump detected!
Apr 19 11:15:10 .. chronyd[1853]: Can't synchronise: no selectable sources
Apr 19 11:18:23 .. chronyd[1853]: Selected source 45.76.113.31
Apr 19 11:18:23 .. chronyd[1853]: System clock wrong by 16380213.742276 seconds, adjustment started
Apr 19 11:18:24 .. chronyd[1853]: Selected source 169.254.169.123

Eventually chronyd will bring the time back to the correct one. If you want to use the instance with a wrong time you'll have to stop chrony:

[root@ip-172-31-31-74 ~]# systemctl stop chronyd.service 

Hope that helps :)

MLu
  • 24,849
  • 5
  • 59
  • 86
-2

¿Have you checked your timezone? You can check you /etc/timezone file if your machine is a debian distribution

Best

-2

Use ntp, easy to set and will synchronize you local time with the peers yo set.

Ali Mezgani
  • 3,850
  • 2
  • 24
  • 36
  • 1
    OP **has** something like `ntp` in place. They're trying to set an *invalid* date, and are confused about what's fixing it. (That'd be `ntp`.) – ceejayoz Oct 25 '18 at 19:22