Tuesday, November 27, 2012

Duplicate ssh sessions without password prompt

I work with multiple ssh sessions whenever I connect to a server. Typically I would have about 3 sessions initiated from my host machine to the destination server.
Found away to duplicate my session without retyping my password every time I initiate a connection the the server from my host machine thanks to  Linux By Examples.
Add the following 2 lines to your /etc/ssh/ssh_config file and feature will be ready for you to use once you restart the sshd service.
ControlMaster auto
ControlPath ~/.ssh/socket-%r@%h:%p

ssh-dup.jpg
ControlMaster
Enables the sharing of multiple sessions over a  single
network  connection.   When  set  to  “yes”  ssh will
listen for connections on a  control  socket  specified
using  the  ControlPath  argument.  Additional sessions
can connect to this socket using the  same  ControlPath
with  ControlMaster set to “no” (the default).  These
sessions will reuse the master instance’s network  con-
nection  rather than initiating new ones.  Setting this
to “ask” will cause ssh to listen for control connec-
tions,  but  require confirmation using the SSH_ASKPASS
program before they are accepted  (see  ssh-add(1)  for
details).
ControlPath
Specify  the  path  to  the  control  socket  used  for
connection sharing.  See ControlMaster above.