docstr: set up ssh tunnels, if needed.
docstr_tok: ["set","up","ssh","tunnels",",","if","needed","."]
code: def init_ssh(self):
      """set up ssh tunnels, if needed."""
      if not self.existing or (not self.sshserver and not self.sshkey):
          return
      self.load_connection_file()
  
      transport = self.transport
      ip = self.ip
  
      if transport != "tcp":
          self.log.error(
              "Can only use ssh tunnels with TCP sockets, not %s",
              transport,
          )
          sys.exit(-1)
  
      if self.sshkey and not self.sshserver:
          # specifying just the key implies that we are connecting directly
          self.sshserver = ip
          ip = localhost()
  
      # build connection dict for tunnels:
      info = dict(
          ip=ip,
          shell_port=self.shell_port,
          iopub_port=self.iopub_port,
          stdin_port=self.stdin_port,
          hb_port=self.hb_port,
      )
  
      self.log.info(
          "Forwarding connections to %s via %s" % (ip, self.sshserver)
      )
  
      # tunnels return a new set of ports, which will be on localhost:
      self.ip = localhost()
      try:
          newports = tunnel_to_kernel(info, self.sshserver, self.sshkey)
      except:
          # even catch KeyboardInterrupt
          self.log.error("Could not setup tunnels", exc_info=True)
          self.exit(1)
  
      (
          self.shell_port,
          self.iopub_port,
          self.stdin_port,
          self.hb_port,
      ) = newports
  
      cf = self.connection_file
      root, ext = os.path.splitext(cf)
      self.connection_file = root + "-ssh" + ext
      self.write_connection_file()  # write the new connection file
      self.log.info("To connect another client via this tunnel, use:")
      self.log.info(
          "--existing %s" % os.path.basename(self.connection_file)
      )
  
imports: import atexit
  import os
  import signal
  import sys
  import uuid
  import warnings
  from traitlets.config.application import boolean_flag
  from ipython_genutils.path import filefind
  from traitlets import Dict, List, Unicode, CUnicode, CBool, Any
  from jupyter_core.application import base_flags, base_aliases
  from .blocking import BlockingKernelClient
  from .restarter import KernelRestarter
  from .None import KernelManager, tunnel_to_kernel, find_connection_file, connect
  from .kernelspec import NoSuchKernel
  from .session import Session
  from .localinterfaces import localhost
label_desc: Use image node_id 4 for calling the JupyterConsoleApp obj's underlying member method code with example usage: obj.init_ssh() without return types