Date and time

How to change the date and time on your controller.

Setting the date and time correctly is important for validating connection certificates. If the date on the controller differs too much from the date on the machine that is trying to connect, you may not be able to connect and you may see “Invalid Certificate” errors reported in your browser.

To set the correct time, log in to your controller via ssh. See Remote Access and file transfer.

Setting date and time

To check the current date and time, type the following in the terminal:

date

The date and time can be set by executing the following Linux command (as root):

sudo date -s "Mon Mar 15 18:49:40UTC 2019"
sudo hwclock -w

The last line is important because only then the time is set correctly in the hardware clock and is not lost on reboot.

If your controller has access to another Linux machine on the network you can also grab the time from that system easily by using the following command (replace [USER] and [OTHER_SYSTEM] with the username and hostname/ip of the other system respectively:

sudo date -s "$(ssh [USER]@[OTHER_SYSTEM]  'date -Ins')"
sudo hwclock -w

Setting date and time via ssh from a Linux host

You can also copy the date and time from a Linux machine to the target controller. You can do this from the controller or from the host machine; the first method is more secure since it does not require using the password in clear text.

Setting time from the controller

To execute the date setting from the controller, first log in to the controller via ssh:

ssh admin@192.168.2.100

Then run the following command, where you replace [user] by the username and [ip] by the hostname or ip address of the host machine where you would like to copy the time from:

sudo echo; D=$(ssh [user]@[ip] 'date -Ins'); sudo date -s $D; sudo hwclock -w

You will first be asked for the password of the admin user on the controller and then for the password of the [user] of the host machine.

Using this command the time on the controller should be set very close to the time of the target machine.

Setting time from the host (insecure!)

To avoid a delay between reading the time on the host and setting it on the target it is recommended to enable automatic ssh login via your public key. Copy your public key to the target like this (assuming your public key is in ~/.ssh/id_rsa.pub):

ssh-copy-id -i ~/.ssh/id_rsa.pub admin@192.168.2.100

You have to enter the admin user’s password once to copy the key, after that connecting to the machine should not require your password any more.

Execute the following script to read the time in UTC on you local machine and set it via ssh on the remote machine. Since the date -s command requires sudo you can pass the password in clear text by using the echo command and the -S switch for the sudo command. Note that this is a security risk, you should not store this command anywhere and make sure your command history is cleared afterwards:

D=`date -Ins`; echo $D; ssh -t admin@192.168.2.100 'echo vectioneer | sudo -S date -s '$D'; sudo hwclock -w'

To mitigate the risk of someone reading your password in the history delete the command history on your local machine by executing:

history -c

This should not be necessary on the controller, since executing ssh command on the remote machine does not add the command to that machine’s history.

Setting the Timezone

First, set the timezone by replacing the link /etc/localtime with a link that points to the desired timezone:

sudo rm -f /etc/localtime 
sudo ln -sf /usr/share/zoneinfo/Universal /etc/localtime

Replace Universal with your desired region or timezone.

The default setting is Universal Time.