[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: ssh tunnel help



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


Reply to: