Support #834
Persistent Reverse SSH Tunnel Using AutoSSH on FreeBSD
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
- And add the following:
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 &
- And add the following:
- Run the script to start the tunnel without rebooting:
sh /etc/rc.local
Resources¶
Updated by Daniel Curtis over 8 years ago
- Description updated (diff)
- Status changed from New to Resolved
- % Done changed from 0 to 100