Friday, January 27, 2012

Create a Firefox proxy through an SSH tunnel to Amazon EC2 instance

You can create an SSH tunnel to a server for Firefox in order to secure your web browsing - when on a public hotspot... or it can be used for other creative reasons for hiding your IP and routing your web traffic through another server :) that serves as a proxy.
I will use connection to Amazon EC2 instance as an example but it should work with any server to which you can log in remotely:

1. make sure that your server accepts SSH connections (port 22 incoming). If you're using the EC2 severs, this needs to be configured via their security groups (including the IP range for which the connection is allowed

2. connect to your server using this command (from Linux terminal (bash))   

ssh -i key.pem -D 9999 -C user@IP_or_server_name 

Replace the 'key.pem' with your private key file (if you need a private key for the connection), then replace user and IP... with your user credentials.

For Windows, use the PUTTY program. You will need to convert your private key file to a format that PUTTY supports- to do this, use the PUTTY gen utility.

3. verify that the connection is established

4. once verified, go to Firefox -> Edit -> Preferences -> Advanced -> Network -> Settings and enter the following preferences:
You should now be able to browse the web through the proxy in Firefox. Check your IP (try googling 'my ip'), the address should be the one of your server.





Connect to a MySQL database through an SSH tunnel

I recently signed up to the Amazon EC2 service and I was testing it- so far it looks very good. I didn't yet test the RDS service Amazon offer for MySQL. However I installed MySQL in the EC2.

In this post I will show how to connect to a MySQL database on the EC2 server (this should work with any remote server) and the Navicat MySQL client (great piece of software BTW).

  1. Open a new connection tab in Navicat (or any other MySQL client supporting connection via SSH tunnel. The default MySQL query browser doesn't support this).
  2. Enter the following parameters. Replace the user and password with your login details for the MySQL database on the server. Leave the server name as localhost, this is the host that the client will connect to once connected to the server.


3. Now go to the SSH tab. 
Enter the following parameters:
Host name/ IP address: this is the public DNS name of your server/ server instance or its IP/ EIP
Port 22
Username: user for your server
Authentication metod: Public key in case of the EC2 instance
Private key: load up your private key
Passphrase: empty for the EC2 connection

-> OK. And voila. Enjoy
Hello world,

This is my first blog. I intend to blog about tech stuff- I especially like to play around with open source software, dabatases (MySQL) etc.


Hope you find it useful.