Can I change ssh port forwardings on a active connection *non-interactively* ?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Can I change ssh port forwardings on a active connection *non-interactively* ?

Manolis Tzanidakis-2
Hello all,
I want to send the '~C' escape to ssh followed by ie. '-L 1024:localhost:1024'
from the active ssh connection's shell, non-interactively from a script.
Is it possible? Or is there a better way to accomplish this?


I'm trying to build an idiot-proof menu for non tech savvy users to allow them
create a couple of tunnels to local services (on different ports), on demand.
The script needs to run a bunch of other stuff after adding the tunnels, so I
can't just tell them to pass '-L etc.' to the client..

--
Manolis Tzanidakis
http://mtzanidakis.com/
mtzanidakis[at]gmail[dot]com

Reply | Threaded
Open this post in threaded view
|

Re: Can I change ssh port forwardings on a active connection *non-interactively* ?

Alexander Hall
On 11/15/12 23:10, Manolis Tzanidakis wrote:
> Hello all,
> I want to send the '~C' escape to ssh followed by ie. '-L 1024:localhost:1024'
> from the active ssh connection's shell, non-interactively from a script.
> Is it possible? Or is there a better way to accomplish this?

Without judging the reason, `ssh -t` might be a good start.

/Alexander

>
>
> I'm trying to build an idiot-proof menu for non tech savvy users to allow them
> create a couple of tunnels to local services (on different ports), on demand.
> The script needs to run a bunch of other stuff after adding the tunnels, so I
> can't just tell them to pass '-L etc.' to the client..

Reply | Threaded
Open this post in threaded view
|

Re: Can I change ssh port forwardings on a active connection *non-interactively* ?

Manolis Tzanidakis-2
On Thu (15/11/12), Alexander Hall wrote:
> On 11/15/12 23:10, Manolis Tzanidakis wrote:
> >Hello all,
> >I want to send the '~C' escape to ssh followed by ie. '-L 1024:localhost:1024'
> >from the active ssh connection's shell, non-interactively from a script.
> >Is it possible? Or is there a better way to accomplish this?
>
> Without judging the reason, `ssh -t` might be a good start.

Hey there,
thanks for answering. Could you be more specific pls? I'm not sure how
this could help. All users will have regular logins (pseudo-ttys) and
can send escape sequences to ssh.
>
> >I'm trying to build an idiot-proof menu for non tech savvy users to allow them
> >create a couple of tunnels to local services (on different ports), on demand.
> >The script needs to run a bunch of other stuff after adding the tunnels, so I
> >can't just tell them to pass '-L etc.' to the client..

Let me rephrase this to avoid further misunderstandings. I've got this
scenario (anything prior to '$' is the hostname):

userbox$ ssh [hidden email]
foo.bar$ printf "%s@%s\n" "`whoami`" "`hostname`"
[hidden email]

Let's say the user wants to add a tunnel to her current ssh connection
for accessing httpd running on server foo.bar. The httpd listens on
localhost only.
I want to automate this process:

foo.bar$ ~C
ssh> -L 2000:localhost:80
Forwarding port.

--
Manolis Tzanidakis
http://mtzanidakis.com/
mtzanidakis[at]gmail[dot]com

Reply | Threaded
Open this post in threaded view
|

Re: Can I change ssh port forwardings on a active connection *non-interactively* ?

Darren Tucker
In reply to this post by Manolis Tzanidakis-2
On Fri, Nov 16, 2012 at 12:10:19AM +0200, Manolis Tzanidakis wrote:
> Hello all,
> I want to send the '~C' escape to ssh followed by ie. '-L 1024:localhost:1024'
> from the active ssh connection's shell, non-interactively from a script.
> Is it possible? Or is there a better way to accomplish this?

If you start ssh with ControlMaster mode enabled you can use "ssh -O
forward" to add forwardings to an established connection, eg:

$ ssh -o ControlMaster=yes -o ControlPath=/tmp/ctl localhost

$ ssh -o ControlMaster=no -o ControlPath=/tmp/ctl -O forward \
    -L 1234:127.0.0.1:22 localhost

--
Darren Tucker (dtucker at zip.com.au)
GPG key 8FF4FA69 / D9A3 86E9 7EEE AF4B B2D4  37C9 C982 80C7 8FF4 FA69
    Good judgement comes with experience. Unfortunately, the experience
usually comes from bad judgement.

Reply | Threaded
Open this post in threaded view
|

Re: Can I change ssh port forwardings on a active connection *non-interactively* ?

Manolis Tzanidakis-2
On Sun (18/11/12), Darren Tucker wrote:

> On Fri, Nov 16, 2012 at 12:10:19AM +0200, Manolis Tzanidakis wrote:
> > Hello all,
> > I want to send the '~C' escape to ssh followed by ie. '-L 1024:localhost:1024'
> > from the active ssh connection's shell, non-interactively from a script.
> > Is it possible? Or is there a better way to accomplish this?
>
> If you start ssh with ControlMaster mode enabled you can use "ssh -O
> forward" to add forwardings to an established connection, eg:
> $ ssh -o ControlMaster=yes -o ControlPath=/tmp/ctl localhost
> $ ssh -o ControlMaster=no -o ControlPath=/tmp/ctl -O forward \
>     -L 1234:127.0.0.1:22 localhost

I've tested some options (including ControlMaster) with one of the
will-be users of this system and I think I should abandon this plan
altogether and give me them pre-defined ssh_configs and putty confs
instead.

Anyway, thanks for your time Darren and Alexander.

--
Manolis Tzanidakis
http://mtzanidakis.com/
mtzanidakis[at]gmail[dot]com