You can make connections faster for ssh, rsync, hg, git, emacs, etc by using a shared ssh connection instead of creating a new connection every time.

Method One - .ssh/config#

Add the following to your ~/.ssh/config.

Host *
  ControlPath ~/.ssh/master-%l-%r@%h:%p
  ControlMaster auto

If you want aliases created, you can also add

Host machine1
  User yourname
  HostName machine1-long-name.domain.com

Host machine2
  User yourname
  HostName machine2-long-name.domain.com

Now, instead of typing

$ ssh [yourname@]machine1-long-name.domain.com

You can simply do

$ ssh machine1

Any subsequent connections that machine will be very fast and use the same connections.

More information

Making a new connection#

If you want to use a different connection options, you must open a new connection instead if reusing the existing one. You do this by setting the ControlPath to none. For convenience, the -S flags sets the ControlPath on a per-process basis.

$ ssh -S none -Y example.com

Method Two - For Emacs#

If you only want to improve your emacs performace, in your ~/.emacs file, add

(require 'tramp)
(setq tramp-default-method "scpc")

When you open a file, open as

/host:/path/to/file

It will be noticably faster.


Networking.SSH : Performance