ssh tunneling to aws instance

Tunneling to AWS instance using pem file

How to tunnel to bastion instance using ssh tunneling

Usually you are going to need this on jump server or what we bastionwhitelist your IP to the corresponding server before you attempt to ssh tunnel to it.

How do I do that?

Go to your terminal and issue

ssh -i /PATH/TO/YOUR-PEM-FILE.pem -N -L 3308:YOUR-RDS-SERVER:3306 ec2-user@YOUR-AWS-SERVER-IP-OR-NAME

What is happening?
You will get your pem file and use that as a token to jump to your server. In this example I gave and RDS of mysql which by default has port of 3306. And I have given 3308 which will be used from my machine to jump to the server as needed.

what then?

Now, your local machine is configured to relay – forward – the port to the destination and whatever you throwing to your local machine’s 3308 port will be forwarded to the remote servers port and you can access the RDS.

Configuring PHP + MySQL + Apache on Amazon EC2 Step by Step

Log in to aws.amazon.com
Click on EC2 virtual servers in the cloud

From the left menu, under Network and Security, select Key Pairs
Create on by hitting “Create Key Pair”. Mind you, aws will give you only one chance to save the pem file you will be using for logging. So make sure you download and save it.

From your select Elastic Beanstalk and follow the wizard to create an instance per your need.
in the wizard, there is a step you will be asked to use the pem file you downloaded.

Now from the left menu, click on the instances.
And click on the instance on the right pane and you will see another pane with description will be opened on the lower part. On that pane, search for security group and click the link
You will be transferred to the security group associated with that instance. Click on the “in bound” tab and check if SSH is listed there, if not, hit the ‘Edit’ button and add a new rule of SSH with the source of anywhere if you would like to ssh into your box from anywhere or you can specify particular ip address.

log to your instance from terminal as

ssh -i /your/downloaded/pem/file ec2-user@public-domain-goes-here

you will get your public domain on the instance you selected.

If you are using Elastic Beanstalk, it will come with installed apache server for as your webserver. Just restart it

sudo service httpd restart

MySQL shell would be there as well but not the mysql server so install that

sudo yum install -y mysql-server

And restart the demon

sudo service mysqld restart

I have checked if git is installed, if you are using any DCVS, which you should and it is installed already to verify do

git --version

Next would be the creation of your public and private keys for secure communication with the other servers.

ssh-agent -t rsa -b 4096 "your_email@domain.tld"

The above command will provide you with the public and private key that you would use. The default path for it would be on ~/.ssh/id_rsa and ~/.ssh/id_rsa.pub

If you are using github or bitbucket, you would need the content of the id_rsa.pub for logging to the server without password.

If you are going to use mongo just use the very information on the following links https://docs.mongodb.org/ecosystem/platforms/amazon-ec2/
http://www.liquidweb.com/kb/how-to-install-the-mongodb-php-driver-extension-on-centos-6/

This will get you started with your aws instance