How to set current time on Linux without ntp or rdate

On Linux or unix machines where you have only limited access to the Internet (for example, only http / https allowed), you can still set the current date and time, relying for the exact time on a trusted web server.

In the example below the website is used:

date --set="$(wget -S -O - 2>&1 >/dev/null | sed -n 's/.*Date: \(.*\)$/\1/p')"

You can check before if the server has a correct date and time by typing:
date -d "$(wget -S -O - 2>&1 >/dev/null | sed -n 's/.*Date: \(.*\)$/\1/p')"

Leave a Reply

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