Project

General

Profile

Support #834

Persistent Reverse SSH Tunnel Using AutoSSH on FreeBSD

Added by Daniel Curtis over 8 years ago. Updated over 8 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
SSH Server
Target version:
Start date:
07/29/2016
Due date:
% Done:

100%

Estimated time:
0.50 h
Spent time:

Description

This is a guide for setting up a persistent reverse SSH tunnel using AutoSSH on FreeBSD.

Once completed, the service that will autostart at boot will open port 5000 on the remote SSH connection that will allow SSH connections back to the originating host.

Prepare the Environment

  • Switch to the root user:
    sudo -s
    
  • Make sure the system is up to date:
    pkg update && pkg upgrade
    
  • Generate a root ssh keypair:
    ssh-keygen -t ed25519
    
  • Copy the ssh public key to the remote host:
    ssh-copy-id bob@ssh.example.com
    

AutoSSH

  • Install autossh:
    pkg install autossh
    

Host Config

  • Create a .ssh config file:
    vi ~/.ssh/config
    
    • And add the following:
      Host remote-tunnel-home
         HostName      ssh.example.com
         User          bob
         Port          7022
         IdentityFile  ~/.ssh/id_ed25519
         RemoteForward  5000 localhost:22
         ServerAliveInterval 30
         ServerAliveCountMax 3
      

Start Tunnel at Boot

  • Edit the rc.local file:
    vi /etc/rc.local 
    
    • And add the following:
      #!/bin/sh
      
      /usr/local/bin/autossh -M 0 -N remote-tunnel-home &
      
  • Run the script to start the tunnel without rebooting:
    sh /etc/rc.local
    

Resources

#1

Updated by Daniel Curtis over 8 years ago

  • Description updated (diff)
#2

Updated by Daniel Curtis over 8 years ago

  • Description updated (diff)
  • Status changed from New to Resolved
  • % Done changed from 0 to 100
#3

Updated by Daniel Curtis over 8 years ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF