This is an old revision of the document!


Raspian 10

Prepare SD card

Install OS

  • Boot from SD card
  • Update all packages
  • Enable SSH server in Interface Options and set location and keyboard in Localisation Options:
    sudo raspi-config
  • Change host name
  • Config SSH and generate SSH keys
  • Exchange public key files
  • Install missing packets:
    apt install autossh vim

Install AutoSSH

Install AutoSSH on a remote_host to connect to my main server (local_host) to allow connections from any_host (either at the local location, or at any other remote location) back to the remote host.

Remote location

  1. Verify access from local_host and any_host: SSH from remote_host to local_host:<ssh_port_local_host> with key pair authentication and establish tunnel, requires <ssh_port_local_host> to be open on local location:
    remote_host$ ssh -R <port_to_access_remote_from_local>:localhost:22 user@<domain_name_of_local_host> -p <ssh_port_local_host>
  2. Once confirmed, create file autossh-tunnel.service in /etc/systemd/system/:
    [Unit]
    Description=AutoSSH tunnel service Remote port <port_to_access_remote_from_local> to local 22
    After=network.target
    
    [Service]
    Environment="AUTOSSH_GATETIME=0"
    ExecStart=/usr/bin/autossh -o "ServerAliveInterval 10" -o "ServerAliveCountMax 3" -N -R <port_to_access_remote_from_local>:localhost:22 user@<domain_name_of_local_host> -p <ssh_port_local_host> -i /home/pi/.ssh/id_ecdsa
    
    [Install]
    WantedBy=multi-user.target

Local location

  1. Verify: SSH from local_host to remote_host through tunnel at <port_to_access_remote_from_local>
    local_host$ ssh pi@localhost -p <port_to_access_remote_from_local>

Any location

  1. Verify: SSH to local_host and establish tunnel from (any_host) <port_to_access_remote_from_local> to localhost:<port_to_access_remote_from_local>
  2. Verify: SSH from any_host to localhost:<port_to_access_remote_from_local>