# ssh multiplexing (ControlMaster) and forwards

## Massimo B.

Hi,

I got to know the powerful ssh multiplexing by using ControlMaster auto that makes remote connections faster and more responsive.

However since I enabled that, the way of adding forwards like

```
ssh -N -L <port>:<host>:<port> host2 &
```

makes that terminal very slow, only accepting every 2nd keystroke. On the other hand the connection is only working when hitting enter on that terminal. It seems that multiplexing makes the forward not correctly detaching by &. Without & the forward works well.

btw. what is the Gentoo way of adding those forwards by OpenRC when the connection is up? Usually those forwards are breaking after Supend-to-ram or network issues. I'd like to restart the forward automatically.

I was looking if shorewall can do the forwards, as shorewall also has some ifup ifdown scripts, but the #shorewall people say that is out of shorewall scope.[/code]

----------

## Hu

You should not place ssh in the background using the shell.  Instead, you should use -f to ask ssh to place itself in the background (and stop reading from your terminal) after it authenticates.

----------

## Massimo B.

Thanks. While trying to make dropped forwards restarting and more reliable I looked at autossh. But can that be used for this kind of forward? Reading the man mage I tried replacing the ssh command with autossh, but failing:

```
autossh  -N -L <port>:<host>:<port> host2
```

That was about restarting broken connections. However with more than 2 or 3 such forwards it could be worth to look at sshuttle. But that would forward everything by default, if not creating some dummy interface and some iptable rules myself to forward only per destination host or port.

As for the performance, sshuttle explains about the bad situation of tcp-over-tcp tunnels, seriously improved by sshuttle, but is this the case when forwarding tcp connection multiplexed (ControlMaster) over ssh?

----------

## Ant P.

 *Massimo B. wrote:*   

> btw. what is the Gentoo way of adding those forwards by OpenRC when the connection is up? Usually those forwards are breaking after Supend-to-ram or network issues. I'd like to restart the forward automatically.

 

OpenRC will not restart the process automatically after it dies so this is not possible there. I have this kind of setup on my laptop, but I use runit (same command line, no -f or &).

----------

## Massimo B.

Reading that runit is a sysvinit replacement, is it also a complete replacement of OpenRC or systemd? I don't think I would like that way. OpenRC should also have a method to restart a killed process.

btw. if using -f I don't see at all if connections are broken. With & before I had at least the "Broken pipe.." on stdout from the background process. I guess for now I just spend some terminals and use ssh without -f, I can detect if it is killed and restart. I could even insert it into while true;do ssh...;done. But these loops are a bit tricky to kill in general as one need to kill the parent shell.

----------

