Skip to content

Instantly share code, notes, and snippets.

@exiguus
Created June 11, 2020 12:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save exiguus/7e704da5280b0fd1482642f377b6bd99 to your computer and use it in GitHub Desktop.
Save exiguus/7e704da5280b0fd1482642f377b6bd99 to your computer and use it in GitHub Desktop.
SSH Multiplexing

SSH Multiplexing

In OpenSSH, multiplexing can re-use an existing outgoing TCP connection for multiple concurrent SSH sessions to a remote SSH server, avoiding the overhead of creating a new TCP connection and reauthenticating each time. (https://en.wikibooks.org/wiki/OpenSSH/Cookbook/Multiplexing)

  • sshuttle
  • ssh

sshuttle

Multiplex by default (https://sshuttle.readthedocs.io/en/stable/how-it-works.html)

For example tunnel NS service:

/usr/bin/sshuttle --ns-hosts 192.168.0.1 -r dns-service-user@ns.local 254.254.254.254/32

ssh

ssh config

~/.ssh/config or /etc/ssh/ssh_config example for all connections

Host *
# Multiplex
    ControlMaster auto 
    ControlPath ~/.ssh/controlmasters/%C
    ControlPersist 2h

NOTE: mkdir ~/.ssh/controlmasters/ or /root/.ssh/controlmasters before run the first connection

CMD

ssh -M -S /home/fred/.ssh/controlmasters/fred@server.example.org:22 server.example.org

Then for subsquent Multiplex

ssh -S /home/fred/.ssh/controlmasters/fred@server.example.org:22 server.example.org
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment