Author: Marc Abramowitz
The reduced connection times that the ControlMaster feature provides are particularly nice when you’re using tools that open multiple SSH connections to do work on a remote server, such as:
- Using Emacs on the client with Transparent Remote (file) Access, Multiple Protocol (TRAMP) to access files on a remote server via SSH
- Using the SSH Filesystem (SSHFS) feature of Filesystem in Userspace (FUSE)
- Accessing a remote Concurrent Versioning System (CVS) or Subversion repository via an SSH tunnel
- Remote filename completion in a shell such as bash or zsh, or in Emacs using TRAMP for that matter
Before setting up the ControlMaster feature, I executed the command
time ssh shifter hostname 10 times to judge the response of a remote system —
shifter is the name of the remote host,
hostname is a single command to execute on the remote host. The average time was 1.9 seconds.
Then I set up the ControlMaster feature by adding the following lines to my ~/.ssh/config:
Host * ControlMaster auto ControlPath ~/.ssh/master-%r@%h:%p
I then opened an SSH connection to shifter and left the connection open while executing the command
time ssh shifter hostname another 10 times. This time, the average time was 0.9 seconds — about half as much as before.
Note that the ControlPath expansion of the remote name (
%r), host (
%h), and path (
%p) only works with OpenSSH 4.2 or newer. If you are using earlier versions in the 4.x series, such as the version of OpenSSH that ships with Ubuntu Breezy, SUSE 10, and Fedora Core 4, you’ll need to do a little extra work to create a ControlMaster connection.
To set up the master connection, run
ssh -M -S ~/.ssh/remote-hostuser@remotehost. Then, run
ssh -S ~/.ssh/remote-hostuser@remotehost for subsequent connections to the same host.
With ControlMaster, you can speed up your SSH connections, and it only takes a few lines in a config file.