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 NET:ERR_CERT_DATE_INVALID 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.

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. he first method is more secure since it does not require using the password in clear text.

Setting time from the target controller

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

ssh admin@192.168.2.100

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

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

You will asked to enter the password of the host machine.

Now you copied the time and date from your host computer to the controller.

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.