Skip to content

Instantly share code, notes, and snippets.

@santaklouse
Last active December 24, 2024 11:15
Show Gist options
  • Save santaklouse/c44b41c055290a6dae35d7966dda1e9b to your computer and use it in GitHub Desktop.
Save santaklouse/c44b41c055290a6dae35d7966dda1e9b to your computer and use it in GitHub Desktop.
bash help scripot for https://ssh-j.com/
#! /usr/bin/env bash
# sshj # Generates a random tunnel ID [e.g. 5dmxf27tl4kx] and keeps the tunnel connected
# sshj foobarblahblub # Creates tunnel with specific tunnel ID
# sshj foobarblahblub 192.168.0.1 2222 # Tunnel to host 192.168.0.1:2222 on the LAN
sshj()
{
local pw
pw="${1,,}"
[[ -z $pw ]] && { pw=$(head -c64 </dev/urandom | base64 | tr -d -c a-z0-9); pw=${pw:0:12}; }
echo "Press Ctrl-C to stop this tunnel."
echo -e "To ssh to ${USER:-root}@${2:-127.0.0.1}:${3:-22} type: \e[0;36mssh -J ${pw}@ssh-j.com ${USER:-root}@${pw}\e[0m"
ssh -o StrictHostKeyChecking=accept-new -o ServerAliveInterval=30 -o ExitOnForwardFailure=yes ${pw}@ssh-j.com -N -R ${pw}:22:${2:-0}:${3:-22}
}
sshj "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment