# launch in backgroundssh -t server screen -S backup -dm backup-nas.sh# attach sessionssh -t server screen -r backup
SSH Forwarding
Local Port Forwarding
# forward the local port to the server on remote portssh -p "$PORT" "$USER"@"$HOST" -L "$LocalPort":localhost:"$RemotePort"
Remote Port Forwarding
# forward requests on remote port to $SERVER:$ServerPortssh -p "$PORT" "$USER"@"$HOST" -R "$LocalPort":$SERVER:"$ServerPort"# forward requests on remote port to local port 2222ssh -p "$PORT" "$USER"@"$HOST" -R "$LocalPort":localhost:2222
Advanced
Reverse SOCKS Proxy
two networks: home & company network
home network allows inbound connections
setup up ssh jump box in home network
we want to setup ssh socks tunnel from jump box to company network
but because we cannot to company network from outside, we create a connection from within to the jump box
then we use remote port-forwarding to connect the jump box back to the company network
when we setup the socks tunnel, we specify a local proxy port and our remote forwarded port
configure jump box as socks proxy on client and browse the web through the eyes of the company network
# from within company boxPROXY_PORT=8888REMOTE_PORT=5555ssh jump@home -t \ # connect to jump box from withing company-R $REMOTE_PORT:localhost:22 \ # forward some remote port from jump box to localhost"ssh -vND $PROXY_PORT localhost -p $REMOTE_PORT" # setup socks proxy on jump box to forwarded port