Try   HackMD
tags: linux

Reverse ssh tunnel

We can use ssh reverse tunnel as an approach to access our local device under the localnet work behind the firewall or NAT.

Please check the detail from Video tutorial

Flow diagram

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

Cmd

ssh -N -R localhost:1234:localhost:22 -i </path/to/ssh/private/key> ubuntu@<cloud.vm.ip.address>

Service file

# /etc/systemd/system/<service.name>.service

[Unit]
Description=Setup a secure tunnel to ubuntu pi
After=network.target

[Service]

ExecStart=/usr/bin/ssh -N -R localhost:1234:localhost:22 -i </path/to/ssh/private/key> -o ServerAliveInterval=60 -o ExitOnForwardFailure=yes ubuntu@<cloud.vm.ip.address>
RestartSec=15
Restart=always

[Install]
WantedBy=multi-user.target