Warning: Undefined array key "ssba_bar_buttons" in /data/f/0/f0e71dcf-4f5a-4882-8c33-9944a28d7ed9/matusbankovic.com/web/wp-content/plugins/simple-share-buttons-adder/php/class-buttons.php on line 602
permanent ssh tunnel - MatusBankovic.com
Categories: Raspberry pi

permanent ssh tunnel


Permanent SSH tunnel

Goal:

How to create and permanent SSH tunnel which is unbreakable and ensure that each time Raspberry Pi A boots or reboots an SSH tunnel to Raspberry Pi B is established automatically?

In case the SSH session will be interrupted for whatever reason, it should be automatically re-established. This can be achieved with help of screen and autossh.

Scenario:

Raspberry pi A with Raspbian OS.

Raspberry pi B with Raspbian OS reachable from the internet via Dynamic DNS.

Solution:
Raspberry pi A:
  1. sudo apt-get update
  2. sudo apt-get upgrade
  3. sudo apt-get install screen
  4. sudo apt-get install autossh
  5. SSH login without password (Ensured that from rpi A to rpi B its possible to login without password)
  6. crontab -e
    • @reboot /usr/bin/screen -S revere-ssh-tunnel -d -m autossh -i /home/user/.ssh/id_rsa -o “ServerAliveInterval 60” -o “ServerAliveCountMax 3” -R 10000:localhost:22 user@server.com -p 22
  7. sudo reboot
  8. screen -ls (way to check if screen session with name reverse-ssh-tunnel exists)
Rasberry pi B:
  1. netstat -nat (way how to check if the tunnel was established and the raspberry pi B is listening on port 10000 )
  2. ssh user@localhost -p 10000 (So it is possible to connect to raspberry pi A)



Matus

Share
Published by
Matus

Recent Posts

Referral links

Listen to radio 1 Listen to radio 2 Listen to radio 3 Listen to radio…

5 years ago

update samsung smart iptv app

Instructions how to update samsung smart iptv app. Bellow instructions also work for all other…

8 years ago

ambient light samsung tv philips hue

What is ambient light samsung tv philips hue? Easy way how to setup ambient light for…

8 years ago

stream popcorn time samsung smart tv

How to stream popcorn time Samsung smart tv? 1.) Simply start to watch a movie…

9 years ago

how find iptv streams

How find iptv streams via google I was searching for "how find iptv streams" on…

9 years ago

windows tips and tricks sites

Following sites are good source of inspiration for tips and tricks for windows, software, gadgets,…

9 years ago