Skip to content

Instantly share code, notes, and snippets.

@kusor
Forked from konobi/info.txt
Created March 12, 2010 15:24
Show Gist options
  • Save kusor/330416 to your computer and use it in GitHub Desktop.
Save kusor/330416 to your computer and use it in GitHub Desktop.
# In .ssh/config:
Host *
ControlMaster no # Connections by default are not a master
ControlPath ~/.ssh/master-%r@%h:%p
ServerAliveInterval 60
ServerAliveCountMax 60
# On normal connections, if there is no master running on the ControlPath it will behave as normal
ssh some.host
# Run autossh (ftp://ftp.sunfreeware.com/pub/freeware/SOURCES/autossh-1.4b.tar.gz)
autossh -f -M 0 -N -o "ControlMaster yes" some.host
# This will setup a daemon that will maintain a "Master" connection to some.host
# Now ssh will use that master channel to connect to some.host
ssh some.host
[jill@ev3-bastion2-prod ~]$ cat .ssh/config
Host *
ControlMaster no
ControlPath ~/.ssh/master-%r@%h:%p
ServerAliveInterval 60
ServerAliveCountMax 60
Host ev3-karma1-a
User jill
Hostname 10.100.100.219
[jill@ev3-bastion2-prod ~]$ ps -efo pid,rss,args | grep autossh |grep -v grep
8647 1132 autossh -f -M 0 -N -o ControlMaster yes ev3-karma1-a
[jill@ev3-bastion2-prod ~]$ netstat -a|grep 10.100.100.219
ev3-bastion2-prod.17062 10.100.100.219.ssh 49640 0 49640 0 ESTABLISHED
ffffff0d57318148 stream-ord ffffff106b4a1600 00000000 /home/jill/.ssh/master-jill@10.100.100.219:22
[jill@ev3-bastion2-prod ~]$ ls -al .ssh/|grep master
srw------- 1 jill jill 0 Mar 12 15:12 master-jill@10.100.100.219:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment