SEL-Columbia / remote-debugger

Portable Raspberry Pi system that enables SSH sessions to a LAN through 3g
MIT License
1 stars 1 forks source link

Remote Debugginator

The Remote Debugginator is a portable Raspberry Pi system that enables remote LAN access through a 3g connection.

It was developed for the Acacia Irrigation project.

Parts List

Raspberry Pi Setup

Booting up video

Wifi network config

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

Install & config screen

We run the 3g and tunnel shell scripts in separate screen windows. This makes it easier to debug should a problem occur.

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install screen

Add this to ~/.screenrc:

    defshell -bash
    multiuser on
    acladd pi

Setup startup scripts

This runs the run.sh script on the Pi's terminal when it boots up.

Add to ~/.bashrc:

    if [ -n "$STY" ]; then
        # Screen session
        echo 'screen session'
    elif [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then
        # SSH Session
        # http://serverfault.com/a/506267
        echo 'ssh session'
    else
        # Main session
        echo 'main session'
        ~/run.sh
    fi

SSH Config

Add to ~/.ssh/config so that the client exits after error (usually it will hang) and disconnects after 3 x 60 seconds of unresponsiveness.

    ExitOnForwardFailure yes
    ServerAliveInterval 60

Generate an SSH key on the Pi by following the guide here. Then copy the Pi’s public key to >~/.ssh/authorized_keys on the DigitalOcean server. This will let the Pi login to the server without a password.

Setup Digital Ocean server

Add this to sudo nano /etc/ssh/sshd_config so that the connection times out after 3 x 60 seconds of unresponsiveness.

ClientAliveInterval 60

Add the repo files to your home folder

    run.sh
    3g.sh
    tunnel.sh

Max out RPi USB power settings

    sudo nano /boot/config.txt

and add,

    max_usb_current=1

to the bottom. Save and exit, then reboot.

Setup 3G

To connect to 3g, we’ll need to install Sakis3g, now seemingly defunct. You cand still get it by instlling UMTSKeeper. UMTSKeeper also helps by automatically reconnecting in the event of a connection failure. It’s a good idea to try UMTSKeeper first in interactive mode.

Test Connection

Test out the reverse tunnel by running this command on the Pi. You’ll want to replace the IP address with the address of your own server.

ssh -R 22222:localhost:22 ubuntu@<IP Address>

If this works, you can log into your server (using a separate terminal) and connect to the Pi via this command:

ssh -p 22222 pi@localhost

Alternate Service Setup

[Unit]
Description=Connect to Cloud Server
After=network-online.target
Wants=network-online.target

[Service]
User=pi
ExecStart=/usr/bin/ssh -g -N -T -o ServerAliveInterval=60 -o ExitOnForwardFailure=yes -R 22222:localhost:22 ubuntu@<IP Address>

StandardOutput=append:/tmp/ssh-service-log-out.log
StandardError=append:/tmp/ssh-service-log-err.log

# Restart every >2 seconds to avoid StartLimitInterval failure
RestartSec=5
Restart=always

[Install]
WantedBy=multi-user.target

Links

Reverse tunneling errors: https://serverfault.com/questions/595323/ssh-remote-port-forwarding-failed

Look into this: https://mosh.mit.edu/#techinfo

How does reverse SSH tunneling work: https://unix.stackexchange.com/questions/46235/how-does-reverse-ssh-tunneling-work

https://blogs.wcode.org/2015/04/howto-ssh-to-your-iot-device-when-its-behind-a-firewall-or-on-a-3g-dongle/