↑ ↓ select, Enter open, Esc close

Reuse SSH connections with ControlMaster

Adjust the values, the command updates live
user@server
ssh -o ControlMaster=auto -o ControlPath=~/.ssh/cm-%C -o ControlPersist=10m webuser@server.example.com

The first connection creates a control socket that all further connections to the same target go through. Additional sessions, scp and rsync therefore start without a new handshake and without a second 2FA prompt. After logging out, ControlPersist keeps the connection open for another ten minutes.

Note: For permanent use, the three options belong in a Host block in ~/.ssh/config. ssh -O exit benutzer@host closes the master connection.

Also searched as

  • ssh connection multiplexing
  • ssh controlmaster controlpersist
  • speed up repeated ssh connections

Related one-liners

All in SSH

Read first, then run.

The commands on myline.de act directly on servers, files and databases. A wrong path or placeholder can delete data irreversibly or make a server unreachable.

  • All commands are provided without warranty and are not tested on every system.
  • Understand what a command does before running it, and check every placeholder.
  • Make a backup first and, if possible, try it on a test system.
  • You run commands at your own risk. Liability for damages is excluded to the extent permitted by law.