Skip to main content
Added an alternative to /etc/inittab for Ubuntu systems with upstart; key-based authentication for reverse SSH tunnel
Source Link

Always use ServerAliveInterval SSH option in case the tunnel issues are generated by expired NAT sessions.

Always use a respawning method in case the connectivity goes down entirely, you have at least three options here:

  • autossh program

  • bash script (while true do ssh ...; sleep 5; done) do not remove the sleep command, ssh may fail quickly and you'll respawn too many processes

  • /etc/inittab, to have access to a box shipped and installed in another country, behind NAT, without port forwarding to the box, you can configure it to create an ssh tunnel back to you:

      tun1:2345:respawn:/usr/bin/ssh -i /path/to/rsaKey -f -N -o "ServerAliveInterval 180" -R 55002:localhost:22 user@publicip 'sleep 365d'
    
  • upstart script on Ubuntu, where /etc/inittab is not available:

      start on net-device-up IFACE=eth0
      stop on runlevel [01S6]
      respawn
      respawn limit 180 900
      exec ssh -i /path/to/rsaKey -N -o "ServerAliveInterval 180" -R 55002:localhost:22 user@publicip
      post-stop script
          sleep 5
      end script
    

or always use both methods.

Always use ServerAliveInterval SSH option in case the tunnel issues are generated by expired NAT sessions.

Always use a respawning method in case the connectivity goes down entirely, you have at least three options here:

  • autossh program

  • bash script (while true do ssh ...; sleep 5; done) do not remove the sleep command, ssh may fail quickly and you'll respawn too many processes

  • /etc/inittab, to have access to a box shipped and installed in another country, behind NAT, without port forwarding to the box, you can configure it to create an ssh tunnel back to you:

      tun1:2345:respawn:/usr/bin/ssh -f -N -o "ServerAliveInterval 180" -R 55002:localhost:22 user@publicip 'sleep 365d'
    

or always use both methods.

Always use ServerAliveInterval SSH option in case the tunnel issues are generated by expired NAT sessions.

Always use a respawning method in case the connectivity goes down entirely, you have at least three options here:

  • autossh program

  • bash script (while true do ssh ...; sleep 5; done) do not remove the sleep command, ssh may fail quickly and you'll respawn too many processes

  • /etc/inittab, to have access to a box shipped and installed in another country, behind NAT, without port forwarding to the box, you can configure it to create an ssh tunnel back to you:

      tun1:2345:respawn:/usr/bin/ssh -i /path/to/rsaKey -f -N -o "ServerAliveInterval 180" -R 55002:localhost:22 user@publicip 'sleep 365d'
    
  • upstart script on Ubuntu, where /etc/inittab is not available:

      start on net-device-up IFACE=eth0
      stop on runlevel [01S6]
      respawn
      respawn limit 180 900
      exec ssh -i /path/to/rsaKey -N -o "ServerAliveInterval 180" -R 55002:localhost:22 user@publicip
      post-stop script
          sleep 5
      end script
    

or always use both methods.

formatting
Source Link
Jawa
  • 3.7k
  • 13
  • 32
  • 38

Always use ServerAliveInterval sshServerAliveInterval SSH option in case the tunnel issues are generated by expired NAT sessions.

Always use a respawning method in case the conectivityconnectivity goes down entirely, you have at least 3three options here:

  • autossh program

    autossh program

  • bash script (while true do ssh ...; sleep 5; done) do not remove the sleep command, ssh may fail quickly and you'll respawn too many processes

    bash script (while true do ssh ...; sleep 5; done) do not remove the sleep command, ssh may fail quickly and you'll respawn too many processes

  • /etc/inittab, to have access to a box shipped and installed in another country, behind nat, with no port forwarding to the box, you can configure it to create an ssh tunnel back to you:

    /etc/inittab, to have access to a box shipped and installed in another country, behind NAT, without port forwarding to the box, you can configure it to create an ssh tunnel back to you:

    tun1:2345:respawn:/usr/bin/ssh -f -N -o "ServerAliveInterval 180" -R 55002:localhost:22 user@publicip 'sleep 365d'
      tun1:2345:respawn:/usr/bin/ssh -f -N -o "ServerAliveInterval 180" -R 55002:localhost:22 user@publicip 'sleep 365d'
    

or always use both methods.

Always use ServerAliveInterval ssh option in case the tunnel issues are generated by expired NAT sessions.

Always use a respawning method in case the conectivity goes down entirely, you have at least 3 options here:

  • autossh program
  • bash script (while true do ssh ...; sleep 5; done) do not remove the sleep command, ssh may fail quickly and you'll respawn too many processes
  • /etc/inittab, to have access to a box shipped and installed in another country, behind nat, with no port forwarding to the box, you can configure it to create an ssh tunnel back to you: tun1:2345:respawn:/usr/bin/ssh -f -N -o "ServerAliveInterval 180" -R 55002:localhost:22 user@publicip 'sleep 365d'

or always use both methods.

Always use ServerAliveInterval SSH option in case the tunnel issues are generated by expired NAT sessions.

Always use a respawning method in case the connectivity goes down entirely, you have at least three options here:

  • autossh program

  • bash script (while true do ssh ...; sleep 5; done) do not remove the sleep command, ssh may fail quickly and you'll respawn too many processes

  • /etc/inittab, to have access to a box shipped and installed in another country, behind NAT, without port forwarding to the box, you can configure it to create an ssh tunnel back to you:

      tun1:2345:respawn:/usr/bin/ssh -f -N -o "ServerAliveInterval 180" -R 55002:localhost:22 user@publicip 'sleep 365d'
    

or always use both methods.

Source Link
claudiuf
  • 351
  • 2
  • 3

Always use ServerAliveInterval ssh option in case the tunnel issues are generated by expired NAT sessions.

Always use a respawning method in case the conectivity goes down entirely, you have at least 3 options here:

  • autossh program
  • bash script (while true do ssh ...; sleep 5; done) do not remove the sleep command, ssh may fail quickly and you'll respawn too many processes
  • /etc/inittab, to have access to a box shipped and installed in another country, behind nat, with no port forwarding to the box, you can configure it to create an ssh tunnel back to you: tun1:2345:respawn:/usr/bin/ssh -f -N -o "ServerAliveInterval 180" -R 55002:localhost:22 user@publicip 'sleep 365d'

or always use both methods.