Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ssh tunnel help

2 views
Skip to first unread message

Nelson Green

unread,
May 22, 2013, 9:20:04 AM5/22/13
to
Hello all,

Seems I'm a bit brain dead this morning, and I'm having difficulty remembering how to set up an ssh tunnel to our development server through the public facing system

I can ssh into pub1 just fine, and from that shell I can ssh into the development server, dev1. What I want to do is to be able to open a terminal on my local machine and connect my psql client directly to that development server, on it's port 5432. So I want to be able to locally run a command similar to:
 [me@mymachine]$ psql -U dbusername -h dev1 -p xxx
where, if I remember correctly, xxx is the port I tunnel into the public system on.
 
I know I've done this before, but since I rarely work from home like this I've forgotten the steps. Would someone care to enlighten me?
 
On a related note, how do I kill the tunnel after I am done with it. I've just killed the process in the past, but I'm wondering if there is not a more elegant way?
 
On a totally unrelated note, I have two old Compaq DL-580 G1s and a few 9GB drives that can go with them. Would any of that be of any value to the Debian project? If so, feel free to point me to a contact person. An off-list reply is perfectly fine.
 
 Thanks,
 Nelson

Darac Marjal

unread,
May 22, 2013, 10:20:02 AM5/22/13
to
On Wed, May 22, 2013 at 08:15:24AM -0500, Nelson Green wrote:
> Hello all,
>
> Seems I'm a bit brain dead this morning, and I'm having difficulty
> remembering how to set up an ssh tunnel to our development server through
> the public facing system
>
> I can ssh into pub1 just fine, and from that shell I can ssh into the
> development server, dev1. What I want to do is to be able to open a
> terminal on my local machine and connect my psql client directly to that
> development server, on it's port 5432. So I want to be able to locally run
> a command similar to:
>  [me@mymachine]$ psql -U dbusername -h dev1 -p xxx
> where, if I remember correctly, xxx is the port I tunnel into the public
> system on.
>  
> I know I've done this before, but since I rarely work from home like this
> I've forgotten the steps. Would someone care to enlighten me?

I'm not sure you can do exactly what you want, but it you issue:

[me@machine]$ ssh my@pub1 -L5432:dev1:5432

then, assuming that pub1 can access port 5432 on dev1, you can do

[me@mymachine]$ psql -U dbusername -h localhost p 5432

So your SSH client listens on localhost:5432 and pub1 connects to
dev1:5432. If you can only access dev1 by ssh and need a second hop,
thinks get more difficult :)

>  
> On a related note, how do I kill the tunnel after I am done with it. I've
> just killed the process in the past, but I'm wondering if there is not a
> more elegant way?

If you close the SSH session, it'll take the tunnel down with it.

signature.asc

Lars Noodén

unread,
May 22, 2013, 10:30:02 AM5/22/13
to
On 5/22/13 4:15 PM, Nelson Green wrote:
> ... connect my psql client directly to that development server, on it's
> port 5432. So I want to be able to locally run a command similar to:
> [me@mymachine]$ psql -U dbusername -h dev1 -p xxx
> where, if I remember correctly, xxx is the port I tunnel into the public
> system on.
>
> I know I've done this before, but since I rarely work from home like this
> I've forgotten the steps. Would someone care to enlighten me?

One way you could try is like this[1]:

ssh -L 5432:localhost:5432 \
-o 'ProxyCommand=ssh -W %h:%p pub1.example.org' \
devel.example.org

Then you would connect to the local host:

psql -U dbusername -h localhost -p 5432

> On a related note, how do I kill the tunnel after I am done with it. I've
> just killed the process in the past, but I'm wondering if there is not a
> more elegant way?

You can close the connection and the tunnel will close.

Or, depending on which version of ssh you have, you can try one of the
ssh escape sequences:

~C
KL5432

Where K is for kill and L or R is the type of forwarding and 5432 is the
actual port. Press ~C? to get the full list of options that are/aren't
available.

Regards,
/Lars

[1] https://en.wikibooks.org/wiki/OpenSSH/Cookbook/Proxies_and_Jump_Hosts


--
To UNSUBSCRIBE, email to debian-us...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listm...@lists.debian.org
Archive: http://lists.debian.org/519CD3F2...@gmail.com

Lars Nooden

unread,
May 22, 2013, 10:40:03 AM5/22/13
to
On Wed, 22 May 2013, Lars Noodᅵn wrote:
> One way you could try is like this[1]:
>
> ssh -L 5432:localhost:5432 \
> -o 'ProxyCommand=ssh -W %h:%p pub1.example.org' \
> devel.example.org

As a follow up here is a method that should work for older versions of ssh:

ssh -L 5432:localhost:5432 -o HostKeyAlias=devel.example.org \
-o ProxyCommand="ssh %h nc devel.example.org 22" \
pub1.example.org

The netcat mode (-W) was added fairly recently.

> [1] https://en.wikibooks.org/wiki/OpenSSH/Cookbook/Proxies_and_Jump_Hosts

Regards,
/Lars
0 new messages