How to configure sshtunnel from raspberry pi towards mysql db

Hi,

I am trying to establish a sshtunnel from a remote raspberry pi client to my NAS drive that has mysql DB installed. When I the client is on the local network I can insert and query data towards the mysql DB via python without any issue on port 3306.
As soon the client is on a different network (so remotely) I can’t figure out how to configure a sshtunnel to access the same mysql DB on the NAS drive (using docker and containerized mysql db).

The NAS drive has ssh enabled on port 22.

On my remote.it I have configured SSH for my NAS drive, like:
remote.it for windows 10 pc:
ssh @nasdrive-ssh.at.remote.it -p 33005 this works from my windows 10 but not on my raspberry pi!?

remote.it for raspberry pi:
ssh @raspberrypi-ssh-nasdrive.at.remote.it -p 33007

is in both cases the same and related to the NAS drive.

What am I doing wrong?

Thanks in adv.

OK it looks like you have 2 devices, one called nasdrive and one called rasberrypi. I am assuming you have remote.it software installed on your raspberry pi and your nas box and your trying to remotely connect from your windows 10 pc?

Its not quite clear where and what you are trying to do. I see your talking about mysql, but your failures seem to be around ssh not mysql.

Please tell me if you have remote.it installed on your NAS, and if you have remote.it installed on the PI and is it the desktop or one line installer?

You should be able to access ssh and mysql (directly from remote.it) on the nas if setup correctly.

Hi,

yes, I do have installed on raspberrypi and on my synology nasdrive remote.it software. I guess my problem is I don’t how to configure remote.it on either of those so I was using the windows remote.it desktop to add services for raspberrypi and my nasdrive and was trying to use the hostnames to create sshtunnel via python module from raspberrypi to my nasdrive.

BTW, the remote.it app on the synology drive is running but it has no other functionality like adding services or so and when open it it always shows “Warning: Undefined array key “claim” in /volume1/@appstore/Remoteit/ui/index.cgi on line 9” although I have done it at the installation phase.

Basically, at the end I would like to be able to access from my raspberrypi (remotely) my docker mysql db on my nasdrive via sshtunnel as everybody is writing is the right way to go.

If you want to run the raspberry pi as a client and not a target, you need to install the desktop or cli on the pi. Then you can setup the connection port on the pi so you can access your synology box.

I’ve never seen that error your experiencing on the synology box, I’ll ask around to see if anyone knows what that is.

Those hostname endpoints you get are only valid on the machine that generated them (they are not public endpoints), you can generate the same URL and port across clients if you use your Organization features.

You can however share client endpoints if you enable lan sharing, but you will have to use the local IP addresses not the remote.it hostnames.

I guess I have now on my raspberry pi cli installed but I am getting the below issue:

pi@raspberrypi:~ $ sudo remoteit status
 × AGENT not reachable, please run 'remoteit agent restart' (CODE: 101)
pi@raspberrypi:~ $ sudo remoteit agent restart
 × Control - Can't find agent (CODE: 405)

What did I do wrong?

It is hard to say without looking at your logs. The Remote.It CLI and the Remote.It Device Package are not compatible.

First, let’s confirm which package you need. I know in this case you need ClI, but for others who might be looking at this post…

The device package which is the one line install code supports inbound connections only. If this is what you need, then you do not need the CLI.
If you need to have this device create remote.it connections to another device (plus it can support inbound connections), then you want the CLI. (for example you would be running a command “sudo remoteit connection add -id xxxx” then use the connection from the device). If you do not need this, again you do not need the CLI and want the Device Package.

Either way, let’s uninstall everything and start fresh. Some of these commands may be unknown which means it wasn’t installed, but we want to be sure.

To uninstall device package

sudo apt purge remoteit

To uninstall CLI

sudo remoteit agent stop
sudo remoteit agent uninstall
sudo remoteit tools uninstall

Then you can remove the CLI binary /usr/bin/remoteit

Let’s get your restore code (if you want to preserve the existing device), or get a new registration code.
You can get your restore code by clicking on the device name in the Remote.It desktop or app.remote.it and then the three dots next to the device name, “Restore Device”, then click the bar code on the bottom right.
To get a new registration code click on “+”, Select the device, the click on the bar code on the bottom right.

Replace XXXXXXXX with your copied code.

If you want to keep the Remote.It CLI:

R3_REGISTRATION_CODE="XXXXXXXX" sh -c "$(curl -L https://downloads.remote.it/cli/install_cli.sh)"

If you want to install the device package , please run the following:

R3_REGISTRATION_CODE="XXXXXXXX" sh -c "$(curl -L https://downloads.remote.it/remoteit/install_agent.sh)"

In either case, you can only use the restore code if you still see the device in your device list. Otherwise you can use the + on the left nav to generate a new registration code.

I decided to go for the cli solution and after I followed your steps uninstalling remoteit and the cli part I continued with the line to install cli, but I got this:

pi@raspberrypi:~ $ R3_REGISTRATION_CODE="xxxxx" sh -c "$(curl -L https://downloads.remote.it/cli/install_cli.sh)"
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  9949  100  9949    0     0  18771      0 --:--:-- --:--:-- --:--:-- 18771
licensekey: xxxxx
Creating registration file
* Distribution: raspbian

* OS: Raspbian

* Installing the remoteit CLI package for x86_64

* CLI Installion:

command: curl -L https://downloads.remote.it/cli/latest/remoteit.x86_64-linux --output /tmp/remoteit
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100 3545k  100 3545k    0     0  1853k      0  0:00:01  0:00:01 --:--:-- 2256k
/usr/bin/remoteit: 3: Syntax error: ")" unexpected
/usr/bin/remoteit: 3: Syntax error: ")" unexpected
/usr/bin/remoteit: 3: Syntax error: ")" unexpected

Any idea what could cause this issue?

I guess it’s obvious that somehow the script gets it wrong and downloads and tries to install for x86_64 because at the some part for Raspbian OS it finds that uname is armv61, see:

pi@raspberrypi:~ $ uname -m
armv6l
pi@raspberrypi:~ $ uname -a
Linux raspberrypi 6.1.21+ #1642 Mon Apr  3 17:19:14 BST 2023 armv6l GNU/Linux

and the if statement it chooses the else for ARCHI=“x86_64”
I assume that remote.it cli is not for raspberry pi zero w with Debian (bullseye):

pi@raspberrypi:~ $ cat  /etc/os-release
PRETTY_NAME="Raspbian GNU/Linux 11 (bullseye)"
NAME="Raspbian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=raspbian
ID_LIKE=debian

So, I guess this can’t be used on the raspberry pi zero.

FYI I think there may be a problem with the old claim code method on the synology. We mostly do not use that method anymore and use registration or license keys which the synology software supports, if you skip this step it will get into the mode your are in.

See: Synology How to Connect Guide

Probably a simple fix, can you run this on the pizero so we can make the detection better:

sh -c “$(curl -L https://downloads.remote.it/remoteit/distributiontest.sh)”

and we can add that to the package

Can you rerun the install on the pi-zero? We patched it to detect the arm6

IE

R3_REGISTRATION_CODE="xxxxx" sh -c "$(curl -L https://downloads.remote.it/cli/install_cli.sh)"

Just the output of the distributiontest.sh:

pi@raspberrypi:~ $ sudo R3_REGISTRATION_CODE="4CC8A5BD-4F10-55FA-8EA9-830304815DAA" sh -c "$(curl -L https://downloads.remote.it/remoteit/distributiontest.sh)"
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  7502  100  7502    0     0   6838      0  0:00:01  0:00:01 --:--:--  6844
~~~~~~ OS INFO ~~~~~~
LSB_RELEASE = raspbian
ETC_ISSUE = raspbian
ETC_EOS_RELEASE =
ETC_OS_RELEASE = raspbian
OPENWRT_RELEASE =
UNAME_S = linux

* Distribution: raspbian

* OS: Raspbian

UNAME_A = Linux raspberrypi 6.1.21+ #1642 Mon Apr  3 17:19:14 BST 2023 armv6l GNU/Linux
UNAME_N = raspberrypi
UNAME_R = 6.1.21+
UNAME_V = #1642 Mon Apr  3 17:19:14 BST 2023
UNAME_M = armv6l
UNAME_P = unknown
UNAME_I = unknown
UNAME_O = GNU/Linux

* ARCH: armhf

* Package Manager(s)
------------
apk=
apt=/usr/bin/apt
apt-get=/usr/bin/apt-get
dnf=
dpkg=/usr/bin/dpkg
ipkg=
rpm=
opkg=
pacman=
smart=
yum=
zypper=
------------

* Docker
------------
docker=
------------

* LSB-RELEASE
------------
No /etc/lsb-release file
------------

* OS-RELEASE
------------
PRETTY_NAME="Raspbian GNU/Linux 11 (bullseye)"
NAME="Raspbian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"
------------

* EOS-RELEASE
------------
No /etc/Eos-release file
------------

* OPENWRT_RELEASE
------------
No /etc/openwrt_release file
------------

* ISSUE
------------
Raspbian GNU/Linux 11 \n \l

------------

~~~~~~ OS INFO ~~~~~~

Printout of the install_cli.sh execution:

pi@raspberrypi:~ $ sudo R3_REGISTRATION_CODE="4CC8A5BD-4F10-55FA-8EA9-830304815DAA" sh -c "$(curl -L https://downloads.remote.it/cli/install_cli.sh)"
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 10083  100 10083    0     0  11765      0 --:--:-- --:--:-- --:--:-- 11765
licensekey: 4CC8A5BD-4F10-55FA-8EA9-830304815DAA
There is already a registration file so skipping license key registration
* Distribution: raspbian

* OS: Raspbian

* Installing the remoteit CLI package for arm-v6

* CLI Installion:

command: curl -L https://downloads.remote.it/cli/latest/remoteit.arm-v6-linux --output /tmp/remoteit
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100 3199k  100 3199k    0     0  1180k      0  0:00:02  0:00:02 --:--:-- 2055k
sh: 159: /usr/bin/remoteit: Exec format error
✓ Installing tools
 ✓ Tools installed to: '/usr/bin/connectd'
 ✓ Tools installed to: '/usr/bin/muxer'
 ✓ Tools installed to: '/usr/bin/demuxer'
 ✓ Agent installed and started successfully

One issue remains, see line sh: 159: /usr/bin/remoteit: Exec format error.

Probably artifacts from the bad run left over, try this first and re-run:

sudo remoteit uninstall
sudo rm /usr/bin/remoteit
sudo rm -rf /etc/remoteit
sudo rm /tmp/remoteit
1 Like

OK, my raspberry and remoteit is up & running with the below setup:

pi@raspberrypi:~ $ sudo remoteit status
 ✓ Fetching status

 owner: abc@gmail.com, deviceRegistered: false, services: 1, connections: 3

 device   | type   | state   | address
-------------------------------------------



 connection                 | type              | state        | address                                        | enabled   | p2p   | failover
------------------------------------------------------------------------------------------------------------------------------------------------
 <serviceID1>    | MySQL (45)        | connected    | <hostname>-mysql.at.remote.it:33060             | true      | true  | false
 <serviceID1>    | SSH (28)          | ready        | <hostname>-ssh.at.remote.it:33022               | true      | false | false
 <serviceID1>    | HTTP (7)          | connected    | https://<hostname>-influxdb.at.remote.it:8086   | true      | true  | false

In my case I don’t even need now to do ssh-tunneling I can directly accessing my DBs with the addresses via python influxdb_client and MySQLdb module.

Many thanks

That’s awesome, thanks for sticking with us so we can make our product better.