title: Exit an SSH Tunnel without closing it
body: <p>I am trying to write a script that sets up a bunch of Port forwarding. That part is working fine, the trouble I'm having is figuring out how to establish an SSH Tunnel and then (basically) <em>detach</em> it from my local without closing the tunnel?</p>
  
  <pre><code>#!/bin/bash
  
  
  # Text (Foreground) Colors
  norm_text='\e[0m'
  black_text='\e[30m'
  red_text='\e[31m'
  green_text='\e[32m'
  yellow_text='\e[33m'
  blue_text='\e[34m'
  magenta_text='\e[35m'
  cyan_text='\e[36m'
  lgray_text='\e[37m'
  dgray_text='\e[90m'
  lred_text='\e[91m'
  lgreen_text='\e[92m'
  lyellow_text='\e[93m'
  lblue_text='\e[94m'
  lmagenta_text='\e[95m'
  lcyan_text='\e[96m'
  white_text='\e[97m'
  
  # Text (Background) Colors
  norm_back='\e[49m'
  black_back='\e[40m'
  red_back='\e[41m'
  green_back='\e[42m'
  yellow_back='\e[43m'
  blue_back='\e[44m'
  magenta_back='\e[45m'
  cyan_back='\e[46m'
  lgray_back='\e[47m'
  dgray_back='\e[100m'
  lred_back='\e[101m'
  lgreen_back='\e[102m'
  lyellow_back='\e[103m'
  lblue_back='\e[104m'
  lmagenta_back='\e[105m'
  lcyan_back='\e[106m'
  white_back='\e[107m'
  #-------------------------------
  
  function menu() {
  echo -e "\t==============="
  echo -e "\t${yellow_text}Port Forwarding${norm_text}"
  echo -e "\t==============="
  echo -e "${green_text}"
  echo -e "1.) Start Port Forwarding"
  echo -e "2.) Stop Port Forwarding"
  echo -e "${norm_text}"
  echo -e "${red_text}5.) Exit${norm_text}"
  echo -e ""
  echo -en "Please enter an option: "
  }
  menu
  read -n1 OPTION
  case "$OPTION" in
      "1")
          echo -e ""
          echo -e ""
          read -p "What is your  z-id?" USER
          USER="$USER"
          ssh -N -L 6111:remote.server.org:8080 -L 6112:remote.server.org:8080 -L 6121:remote.server.org:8080 -L 6122:remote.server.org:8080 -L 6211:remote.server.org:8080 -L 6212:remote.server.org:8080 -L 6214:remote.server.org:8080 -L 6215:remote.server.org:8080 -L 6221:remote.server.org:8080 -L 6222:remote.server.org:8080 -L 6224:remote.server.org:8080 -L 6225:remote.server.org:8080 -L 6311:remote.server.org:8080 -L 6312:remote.server.org:8080 -L 6314:remote.server.org:8080 -L 6315:remote.server.org:8080 -L 6321:remote.server.org:8080 -L 6322:remote.server.org:8080 -L 6324:remote.server.org:8080 -L 6325:remote.server.org:8080 -L 6411:remote.server.org:8080 -L 6412:remote.server.org:8080 -L 6421:remote.server.org:8080 -L 6422:remote.server.org:8080 -L 7111:remote.server.org:8080 -L 7112:remote.server.org:8080 -L 7113:remote.server.org:8080 -L 7121:remote.server.org:8080 -L 7122:remote.server.org:8080 -L 7123:remote.server.org:8080 -L 7211:remote.server.org:8080 -L 7212:remote.server.org:8080 -L 7213:remote.server.org:8080 -L 7221:remote.server.org:8080 -L 7222:remote.server.org:8080 -L 7223:remote.server.org:8080 -L 7311:remote.server.org:8080 -L 7312:remote.server.org:8080 -L 7313:remote.server.org:8080 -L 7321:remote.server.org:8080 -L 7322:remote.server.org:8080 -L 7323:remote.server.org:8080 -L 7411:remote.server.org:8080 -L 7412:remote.server.org:8080 -L 7413:remote.server.org:8080 -L 7421:remote.server.org:8080 -L 7422:remote.server.org:8080 -L 7423:remote.server.org:8080 -L 7511:remote.server.org:8080 -L 7512:remote.server.org:8080 -L 7513:remote.server.org:8080 -L 7521:remote.server.org:8080 -L 7522:remote.server.org:8080 -L 7523:remote.server.org:8080 -L 7611:remote.server.org:8080 -L 7612:remote.server.org:8080 -L 7613:remote.server.org:8080 -L 7621:remote.server.org:8080 -L 7622:remote.server.org:8080 -L 7623:remote.server.org:8080 -L 8111:remote.server.org:7034 -L 8121:remote.server.org:7034 -L 8211:remote.server.org:7034 -L 8221:remote.server.org:7034 -L 8311:remote.server.org:7034 -L 8314:remote.server.org:7034 -L 8321:remote.server.org:7034 -L 8324:remote.server.org:7034 -L 8411:remote.server.org:7034 -L 8421:remote.server.org:7034 "${USER}"@tunnel.server.org
          echo -e ""
          echo -e "Local Port 6111 is now resolving content from \"remote.server.org:8080\""
          echo -e "Local Port 6112 is now resolving content from \"remote.server.org:8080\""
          echo -e "Local Port 6121 is now resolving content from \"remote.server.org:8080\""
          echo -e "Local Port 6122 is now resolving content from \"remote.server.org:8080\""
          echo -e "Local Port 6211 is now resolving content from \"remote.server.org:8080\""
          echo -e "Local Port 6212 is now resolving content from \"remote.server.org:8080\""
          echo -e "Local Port 6214 is now resolving content from \"remote.server.org:8080\""
          echo -e "Local Port 6215 is now resolving content from \"remote.server.org:8080\""
          echo -e "Local Port 6221 is now resolving content from \"remote.server.org:8080\""
          echo -e "Local Port 6222 is now resolving content from \"remote.server.org:8080\""
          echo -e "Local Port 6224 is now resolving content from \"remote.server.org:8080\""
          echo -e "Local Port 6225 is now resolving content from \"remote.server.org:8080\""
          echo -e "Local Port 6311 is now resolving content from \"remote.server.org:8080\""
          echo -e "Local Port 6312 is now resolving content from \"remote.server.org:8080\""
          echo -e "Local Port 6314 is now resolving content from \"remote.server.org:8080\""
          echo -e "Local Port 6315 is now resolving content from \"remote.server.org:8080\""
          echo -e "Local Port 6321 is now resolving content from \"remote.server.org:8080\""
          echo -e "Local Port 6322 is now resolving content from \"remote.server.org:8080\""
          echo -e "Local Port 6324 is now resolving content from \"remote.server.org:8080\""
          echo -e "Local Port 6325 is now resolving content from \"remote.server.org:8080\""
          echo -e "Local Port 6411 is now resolving content from \"remote.server.org:8080\""
          echo -e "Local Port 6412 is now resolving content from \"remote.server.org:8080\""
          echo -e "Local Port 6421 is now resolving content from \"remote.server.org:8080\""
          echo -e "Local Port 6422 is now resolving content from \"remote.server.org:8080\""
          echo -e "Local Port 7111 is now resolving content from \"remote.server.org:8080\""
          echo -e "Local Port 7112 is now resolving content from \"remote.server.org:8080\""
          echo -e "Local Port 7113 is now resolving content from \"remote.server.org:8080\""
          echo -e "Local Port 7121 is now resolving content from \"remote.server.org:8080\""
          echo -e "Local Port 7122 is now resolving content from \"remote.server.org:8080\""
          echo -e "Local Port 7123 is now resolving content from \"remote.server.org:8080\""
          echo -e "Local Port 7211 is now resolving content from \"remote.server.org:8080\""
          echo -e "Local Port 7212 is now resolving content from \"remote.server.org:8080\""
          echo -e "Local Port 7213 is now resolving content from \"remote.server.org:8080\""
          echo -e "Local Port 7221 is now resolving content from \"remote.server.org:8080\""
          echo -e "Local Port 7222 is now resolving content from \"remote.server.org:8080\""
          echo -e "Local Port 7223 is now resolving content from \"remote.server.org:8080\""
          echo -e "Local Port 7311 is now resolving content from \"remote.server.org:8080\""
          echo -e "Local Port 7312 is now resolving content from \"remote.server.org:8080\""
          echo -e "Local Port 7313 is now resolving content from \"remote.server.org:8080\""
          echo -e "Local Port 7321 is now resolving content from \"remote.server.org:8080\""
          echo -e "Local Port 7322 is now resolving content from \"remote.server.org:8080\""
          echo -e "Local Port 7323 is now resolving content from \"remote.server.org:8080\""
          echo -e "Local Port 7411 is now resolving content from \"remote.server.org:8080\""
          echo -e "Local Port 7412 is now resolving content from \"remote.server.org:8080\""
          echo -e "Local Port 7413 is now resolving content from \"remote.server.org:8080\""
          echo -e "Local Port 7421 is now resolving content from \"remote.server.org:8080\""
          echo -e "Local Port 7422 is now resolving content from \"remote.server.org:8080\""
          echo -e "Local Port 7423 is now resolving content from \"remote.server.org:8080\""
          echo -e "Local Port 7511 is now resolving content from \"remote.server.org:8080\""
          echo -e "Local Port 7512 is now resolving content from \"remote.server.org:8080\""
          echo -e "Local Port 7513 is now resolving content from \"remote.server.org:8080\""
          echo -e "Local Port 7521 is now resolving content from \"remote.server.org:8080\""
          echo -e "Local Port 7522 is now resolving content from \"remote.server.org:8080\""
          echo -e "Local Port 7523 is now resolving content from \"remote.server.org:8080\""
          echo -e "Local Port 7611 is now resolving content from \"remote.server.org:8080\""
          echo -e "Local Port 7612 is now resolving content from \"remote.server.org:8080\""
          echo -e "Local Port 7613 is now resolving content from \"remote.server.org:8080\""
          echo -e "Local Port 7621 is now resolving content from \"remote.server.org:8080\""
          echo -e "Local Port 7622 is now resolving content from \"remote.server.org:8080\""
          echo -e "Local Port 7623 is now resolving content from \"remote.server.org:8080\""
          echo -e "Local Port 8111 is now resolving content from \"remote.server.org:7034\""
          echo -e "Local Port 8111 is now resolving content from \"remote.server.org:7034\""
          echo -e "Local Port 8121 is now resolving content from \"remote.server.org:7034\""
          echo -e "Local Port 8211 is now resolving content from \"remote.server.org:7034\""
          echo -e "Local Port 8221 is now resolving content from \"remote.server.org:7034\""
          echo -e "Local Port 8311 is now resolving content from \"remote.server.org:7034\""
          echo -e "Local Port 8314 is now resolving content from \"remote.server.org:7034\""
          echo -e "Local Port 8321 is now resolving content from \"remote.server.org:7034\""
          echo -e "Local Port 8324 is now resolving content from \"remote.server.org:7034\""
          echo -e "Local Port 8411 is now resolving content from \"remote.server.org:7034\""
          echo -e "Local Port 8421 is now resolving content from \"remote.server.org:7034\""
          echo -e ""
          echo -e "Port Forwarding ${red_back}${yellow_text}Active${norm_text}${norm_back}:"
      ;;
  esac
  </code></pre>
  
  <p>As of now, it prompts you for your password and the port forwarding tunnel works great, but my script hangs ... I'd like to have an interactive menu like "Close tunnel" and the such.</p>
  
  <p>I know I have the "-N" option right now, which is "<em>execute no command</em>" ... I've removed it and tried something simple like</p>
  
  <pre><code>remote.server.org:7034 -L 8421:remote.server.org:7034  "${USER}"@tunnel.server.org "sleep 10 &amp;"
  </code></pre>
  
  <p>to pause and then background the job, but that is backgrounding it on the remote system, not here ... but it collapses immediately anyway.</p>
  
  <p>I've researched a bunch and found "-S -O" ... although I've read the MAN page for SSH, I still don't have a firm grasp of how to properly implement it, or if that's even what I'm really looking for.</p>
  
  <p>I hope this makes sense.  Your help is greatly appreciated!</p>