1

Programs that allow remote connections (usually in ssh) typically request a user name/pwd to connect to a remote server: see the below examples from sequelpro and rubymine, respectively:

Sequel pro: Attempting to connect to a remote mysql server via ssh:

connection window sequelpro

Rubymine: Attempting to do server side debugging: connection configuration window rubytime

With Amazon AWS, to connect using SSH you need a private key, and the connection command goes something like this:

ssh -i %privateKeyFileName.pem% ubuntu@server

Question: How do I include this private file to be able to successfully connect using apps like prosql or rubymine?


Update: sequel pro can be done natively.. as for rubymine.. i started by doing ssh tunneling.. so here are the steps:

first: I started an ssh tunnel process on my machine, so that any request made to my localhost:9999 port will be forwarded to aws ip at port 3000:

ssh -l ubuntu -i '/path/to/cert/file/certFile.cer' -L 9999:%aws.ip%:3000 %aws.ip%

second: following these instructions.. i bundled the debase debug gem with my rails project.. and ran the following command:

rdebug-ide --port 3000 -- rvmsudo thin start -p 3000 -e production

third: I changed the production debug settings in my rubymine, and made it point to port 3000 in my localhost like so:

enter image description here

fourth: I initiated the debug process from rubymine..

problem: the debug process started.. but it's telling me that it cannot connect to the mysql server:

/Users/abdullahbakhach/.rvm/rubies/ruby-1.9.3-p484/bin/ruby -e at_exit{sleep(1)};$stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) /Users/abdullahbakhach/.rvm/gems/ruby-1.9.3-p484/gems/ruby-debug-ide-0.4.17/bin/rdebug-ide --port 58053 --dispatcher-port 58054 -- /Users/abdullahbakhach/dev/ruby/icars-web-application-veritopia/script/rails server -b 0.0.0.0 -p 9999 -e production
Fast Debugger (ruby-debug-ide 0.4.17, ruby-debug-base19x 0.11.30.pre12) listens on 127.0.0.1:58053
=> Booting Thin
=> Rails 3.2.13 application starting in production on http://0.0.0.0:9999
=> Call with -d to detach
=> Ctrl-C to shutdown server
/Users/abdullahbakhach/.rvm/gems/ruby-1.9.3-p484@global/gems/actionpack-3.2.13/lib/action_dispatch/http/mime_type.rb:102: warning: already initialized constant PDF
Uncaught exception: Host '78.111.131.68' is not allowed to connect to this MySQL server
Exiting
    /Users/abdullahbakhach/.rvm/gems/ruby-1.9.3-p484/gems/mysql2-0.3.14/lib/mysql2/client.rb:67:in `connect'

I know that if i try to connect directly to the mysql db hosted on the aws machine directly from a random host, it will reject that connection on the same grounds. The idea is to fool the mysql db into thinking that i'm actually connecting to it from within aws..

technically i can do the same thing: i can create another ssh tunnel specifically for the mysql host, but then how do i instruct rubymine to connect to that tunnel for the db?

2 Answers 2

1

You're looking for SSH Tunnelling, to allow you to forward a local port (e.g. 127.0.0.1:9876) to the specific port on the remote server. Find the details here

Here's the gist:

ssh -l <SERVER_USER> -i "<SERVER_SSH_KEY>" \ 
    -L <local-port-to-listen>:<remote-host>:<remote-port> 
    <remote-host>

and here's an example:

ssh -l ubuntu -i "/home/myuser/awskey.pem" -L \
    9999:51.100.80.10:3306 51.100.80.10

In the above example, we forward any requests made to port 9999 on the local machine, to port 3306 (for MySQL) on the destination server (IP: 51.100.80.10) - tunnelled through the SSH port on the destination (typically port 22).

With AWS, that means you'd need to change the Security Groups on the EC2 page to enable SSH access to the server (SSH typically runs at port 22, so you'd need to allow access to that p).

4
  • While SSH tunnelling is a workaround that would probably work, these programs are actually fully capable of native SSH connections - just perhaps not with private key auth.
    – Bob
    Commented Dec 21, 2013 at 11:25
  • yeah @Bob.. that's exactly why I'm asking this question
    – abbood
    Commented Dec 22, 2013 at 4:37
  • @abbood I don't have enough rep to comment on the question, so here goes. 1. MySQL runs on port 3306 by default, not 3000. 2. Have you confirmed that you can SSH into the AWS server on port 22? (Note that this means SSH'ing from your local SSH client, and not through the Connect option on the EC2 screen). Commented Dec 22, 2013 at 14:36
  • @Bob now running into the same issue with mongodb using robomongo!
    – abbood
    Commented May 22, 2014 at 11:13
0

it turns out that sequelpro already offers the option to provide an ssh key.. (i guess it's a bug.. if you click on the ssh option and not see the fields for the key, click back to one of the other two tabs than click again on ssh.. and you should see the following screen:enter image description here

update: see here for a detailed discussion about connecting to sequel pro using ssh tunneling

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .