Setting the date of a UNIX/Linux machine over the network with just ssh

I run into machines from time to time that do not have any method of network time setting installed that I know has an incorrect date or time.They usually do have ssh though, so this is my solution from the host with the bad time:
sudo date `ssh <hostWithGoodClock> "date +%m%d%H%M%C%y.%S"`
or if you are doing this from a computer with ssh access to the device:
ssh %lt;hostWithBadClock> "sudo date $(date +%m%d%H%M%C%y.%S)"

Note, this has issues when it comes to time zones.  Do this only with servers in the same timezone.

One thought on “Setting the date of a UNIX/Linux machine over the network with just ssh

  1. Randall says:

    for OpenBSD’s date:
    sudo date `ssh 192.168.222.113 “date +%C%y%m%d%H%M.%S”`

Leave a Reply

Your email address will not be published. Required fields are marked *