Forums

ssh tunneling failure: Bad local forwarding specification

I am trying to use psql from my local machine to view PostgeSQL databases on PythonAnywhere.com. I am running OS X El Capitan. According to https://www.pythonanywhere.com/forums/topic/3523 I need to set up a local tunnel doing this:

ssh -L 3333:mycoolsite-96.postgres.pythonanywhere-services.com:10096 memberable@ssh.pythonanywhere.com

However, when I do, I get an error message saying 'Bad local forwarding specification'.

The only similar errors I can find relate to an app called Sequel Pro, which I don't have installed.

How can I get ssh tunneling to work on my OS X machine?

I wonder if the OSX version of SSH has a slightly different syntax than the linux one for specifying port forwarding (the -L option)? can you check "man ssh"?

Do not seem to be able to crack the SSH tunneling nut. I know it's a big Internet, but I can't find any ssh tunneling tutorials down at my level. SSH on OS X does have completely different command line flags but I don't know how they work. I think the relevant ones are:

-L [bind_address:]port:host:hostport Specifies that the given port on the local (client) host is to be forwarded to the given host and port on the remote side. This works by allocating a socket to listen to port on the local side, optionally bound to the specified bind_address. Whenever a con- nection is made to this port, the connection is forwarded over the secure channel, and a connection is made to host port hostport from the remote machine. Port forwardings can also be specified in the configuration file. IPv6 addresses can be spec- ified by enclosing the address in square brackets. Only the superuser can forward privileged ports. By default, the local port is bound in accordance with the GatewayPorts setting. How- ever, an explicit bind_address may be used to bind the connection to a specific address. The bind_address of `localhost'' indi- cates that the listening port be bound for local use only, while an empty address or*' indicates that the port should be avail- able from all interfaces.

-D [bind_address:]port Specifies a local ``dynamic'' application-level port forwarding. This works by allocating a socket to listen to port on the local side, optionally bound to the specified bind_address. Whenever a connection is made to this port, the connection is forwarded over the secure channel, and the application protocol is then used to determine where to connect to from the remote machine. Currently the SOCKS4 and SOCKS5 protocols are supported, and ssh will act as a SOCKS server. Only root can forward privileged ports. Dynamic port forwardings can also be specified in the configura- tion file.

No clue how to translate them from the Unix ssh version.

Have a look at this SO question. It looks like there are a few options presented and maybe one of them will work for you.

Was able to get this far after tons of experimentation:

$ ssh myusername@ssh.pythonanywhere.com -L 3322:mysite-96.postgres.pythonanywhere-services.com:10096

Was able to log in with no errors. Then when i tried to use psql like this:

[02:02 ~ $ psql -h localhost -p 3322 -U webdba -d memdb

I got 3 of these errors:

psql: could not connect to server: Connection refused
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 3322?

Seems to me it should be accepting on port 3322 because when I tried to connect using port 3333 it errored out.

Sorry if this is a stupid question, but after you ran the first ssh command, did you open a new terminal to run your second psql command?

ie. if you stop the first ssh command, then the second one will not work.