@TrystanLea
This forum thread has fizzled out into a somewhat detailed consideration of security/privacy.
However if one needs remote access then this will be a security/privacy risk and so it’s a matter of minimising that risk - in my opinion.
Notwithstanding that risk, you’ve expressed an interest in solutions that would enable an Export Backup existing on a remote RPi/emonTx to be downloaded to a local RPi.
Using remote.it and the following script, it is possible to do just that and the script can run in the background as a cronjob not needing to enter usernames or passwords. I’ve garbled my personal info …
#!/bin/sh
## Purpose:
## To use remote.it to connect from RPi A (remote) to another RPi B (local)
## Then to copy a file from RPi A to RPi B
## The task to be completed without the need to input user names or passwords
## Hence - this task can be run as a cronjob on RPi A
## Pre-requisites:
## connectd installed on both RPi A and RPI B
## A provisioning or configuration .txt file must exist on RPi A. This defines the Service ID of the target RPi B. Set autoconnect as 2
## An ssH Service created on both RPi A and RPi B
## id-rsa keys from RPi A must exist on RPi B or be copied to RPi B /home/pi/.ssh/authorized_keys
## Now begin ...
## Define key parameters
DEV_KEY="Q~~~~~~~~~~~~~~~~~~~~5"
USERNAME="j~~~~~~~~~~~~~k"
PASSWORD="~~~~~~~~~~~~~"
DEVICE_ADDRESS="80:~~~~~~~~~~~~~~:1C" ## GUID/ssh Service ID for RPi A
HOSTIP=
## Connect to remote.it and get the response json
foo=$(curl -X POST -H developerkey:"$DEV_KEY" -H Content-Type:application/json \
-H Cache-Control:no-cache -d "{ \"username\":\"$USERNAME\", \
\"password\":\"$PASSWORD\" }" https://api.remot3.it/apv/v27/user/login)
## Extract the response token
foo=${foo##*token'":"'}
foo=${foo%%'","'auth*}
TOKEN=$foo
echo $TOKEN ## This line CAN BE REMOVED after de-bugging
## Get the connection json
foo=$(curl -X POST \
-H "token:$TOKEN" \
-H "developerkey:$DEV_KEY" \
-d "{\"wait\":\"true\",\"deviceaddress\":\"$DEVICE_ADDRESS\", \
\"hostip\":\"$HOSTIP\" }" \
https://api.remot3.it/apv/v27/device/connect)
## Extract the CONNECTION_ID
foo=${foo##*connectionid'":"'}
foo=${foo%%'"}'}
CONNECTION_ID=$foo
echo $CONNECTION_ID ## This line CAN BE REMOVED after de-bugging
##
## NOW DO STUFF ...
## For example - copy a file from RPi A to RPi B
##
date=$(date +"%Y-%m-%d")
scp -i /home/pi/.ssh/id_rsa -P 33300 /var/opt/emoncms/backup/emoncms-backup-$date.tar.gz [email protected]:/home/pi
## Finally close the connection
curl -X POST \
-H "token:$TOKEN" \
-H "developerkey:$DEV_KEY" \
-d "{\"connectionid\":\"$CONNECTION_ID\", \
\"deviceaddress\":\"$DEVICE_ADDRESS\" }" \
https://api.remot3.it/apv/v27/device/connect/stop
exit
The first requirement is to sign up for a remote.it account. This is free and one user with up to 10 devices gets free use under their Fair Use Policy.
Their Guide is comprehensive covering Windows, Mac, Linux and RPi which makes it a bit difficult to follow. Their Support is super responsive.
The first step is to install connectd on each RPi and then using an interactive menu to define each Device (RPi) and the Services you require on each Device. The script above requires the ssH service but also install the web service (you can then access the emoncms Web Interface on the remote RPi ).
I should point out that if REMOTE RPi A is at a remote geographical location then you’ll need to make a ‘service’ visit to perform the above steps. But once done, you’ll have remote access to RPi A and the rest of the setup can be done back at ‘local base’ – in my case from a Windows laptop with an ssH terminal for each RPi open on my desktop.
The next step is to create a provisioning or configuration file on RPi A saved in /home/pi and made executable. The Guide has details. You’ll need the address of the target (ie: RPi B’s –ssH Service). Again follow the Guide. And do use autoconnect 2.
At this stage it’s a good idea to run connectd -f name.of.yr.file.txt & on RPi A from an ssH terminal. You’ll see the connection being made and that things are working to that point.
The script requires 2 bits of data … your Developer Key DEV_KEY so follow the Guide to get that and the DEVICE_ADDRESS which is the ssH Service ID for RPi A. Again follow the Guide.
Finally, in order to avoid entering user names and passwords, do the following on RPi A ssh-keygen Just press ENTER when asked for a passphrase and accept the default location which is … /home/pi/.ssh/id_rsa
Now carefully copy & paste the pi@RPi A key from RPi A /home/pi/.ssh/authorized_keys to RPi B /home/pi/.ssh/authorized_keys
You can now run the script on RPi A (after making it executable) or incorporate it into a cronjob, etc.
In summary – the script opens the remote connection, securely (scp) copies an emoncms-backup export file with today’s date and then closes the remote connection. In my case, a 150MB export file takes 6 mins to copy.
Hope this of interest