Multiplexing is nothing but send more than one ssh connection over a single connection. OpenSSH can reuse an existing TCP connection for multiple concurrent SSH sessions. This results into reduction of the overhead of creating new TCP connections. First, you need to set a ControlMaster to open a Unix domain socket locally.
Tutorial details | |
---|---|
Difficulty | Intermediate (rss) |
Root privileges | No |
Requirements | OpenSSH client+server |
Estimated completion time | 5m |
- Use existing unix socket
- No new TCP/IP connection
- No need to key exchange
- No need for authentication and more
How to setup up multiplexing
Edit $HOME/.ssh/config, enter:vi ~/.ssh/config
Append the following configuration:
Host * ControlMaster auto ControlPath ~/.ssh/master-%r@%h:%p.socket ControlPersist 30mHere is another example:
Host server1
HostName server1.cyberciti.biz
Port 2222
ControlPath ~/.ssh/ssh-mux-%r@%h:%p
ControlMaster auto
ControlPersist 10m
Save and close the file. Where,- Host * or Host server1 : Start ssh configuration.
- HostName server1.cyberciti.biz : The real hostname
- ControlPath ~/.ssh/ssh-mux-%r@%h:%p : Specify the path to the control unix socket used for connection sharing as described above. The variables '%r', '%h', '%p' refer to remote ssh username, remote ssh host, and remote ssh port respectively. You need to set all of these three variables.
- ControlMaster auto : 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. When set to auto, ssh will try to use a master connection but fall back to creating a new one if one does not already exist.
- ControlPersist 10m : Specifies that the master connection should remain open in the background for 10 minutes. With no client connections, the backgrounded master connection will automatically terminate after it has remained idle for 10 minutes.
How do I use it?
Simply start running ssh commands:$ ssh user@host
$ ssh root@v.server1
$ ssh nixcraft@192.168.1.219
How do I verify that Multiplexer is working?
Use any one of the following command to verify that Multiplexer is working properly:$ lsof -U | grep master
OR
$ ssh -O check root@v.server1
Sample outputs:
Can I tell master connection not to accept further multiplexing requests?
Yes, use the following syntax:$ ssh -O stop host
$ ssh -O stop root@v.server1
Pass the exit option instead of stop to cancel all existing connections, including the master connection:
$ ssh -O exit host
$ ssh -O exit root@v.server1
How do I the port forwarding?
The syntax is as follows to forward port 3128 on the local host to port 3128 on the remote host using -L:ssh -O forward -L 3128:localhost:3128 v.server1
You can also specifies the location of a control socket for connection sharing:
ssh -O forward -L 3128:localhost:3128 -S $HOME/.ssh/master-root@v.server1:22 v.server1
See ssh_config man page for more information.
No comments:
Post a Comment