Showing posts with label SSH. Show all posts
Showing posts with label SSH. Show all posts

Thursday, April 12, 2012

Connecting to AWS using the the Terminal on a Mac

Hello again from CyberSpace!!

This post is not class oriented! Yay!

Here I'm going to post how to connect to an Amazon Web Services (AWS) BitNami LAMP instance using the Terminal on a Mac using OSX Snow Leopard 10.6.8. I'm a total noob when it comes to server connections, so hopefully this will help other web beginners like myself. If you are looking for an in-depth or full explanation, turn back now. I'm just trying to help other poor souls trying to hack their way into a server for the first time.

First off, you don't need any new software on a Mac. SSH, the security thingy, comes installed with a Mac, whereas Windows users typically use PuTTY and WinSCP. Connecting from windows is pretty simple. In fact, Amazon has a tutorial for connecting using PuTTY at the time of this post. On a Mac, however, the connection is a little less publicized.

First, you will need a code key .pem file. This should be issued by Amazon when you start an instance. You can check the code key pair associated with the AWS instance from your user console, or download a new one.

Next, you need your terminal. I used spotlight find the terminal, but I believe it is located in the applications folder. Once you are in your tsserminal, type the following:

ssh -i THE FILE PATH TO YOUR CODE KEY ec2-user@AMAZON WEB PATH

The file path should be where you saved your codekey.pem file, and the Amazon Web Path should the from Amazon. You can copy path this by checking your instance and clicking 'Connect'.

Once I did that, I got a happy little error:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: UNPROTECTED PRIVATE KEY FILE! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0644 for '/users/___/codeKey.pem' are too open.
It is recommended that your private key files are NOT accessible by others.
This private key will be ignored.
bad permissions: ignore key: /users/___/codeKey.pem
Permission denied (publickey).


DENIED1!?!?! Crap. Here's where things got a little dicey for me, and I'll warn you as well, in case you are trying something a little different. There are codes in a Mac (maybe PC, but I've never encountered them), that determine the publicity of a file, and who can access it. Apparently, my default permissions for this file were set to 644, and that made ssh sad.

There are lots of different levels of permission out there, as a quick Google search will reveal, but not all are suited for connecting to AWS. To change the code of the file, type the following

sudo chmod 700 /users/____/CodeKey.pem

As in the code before, the '/users/____/CodeKey.pem is the path to your codekey. This changes the permissions for this file to 700, but you can use any number. Hit a couple of help message boards, and you'll find plenty of other security codes out there. I had success with 700 for my BitNami LAMP AWS EC2 instance.

You will be prompted for a password, then the security will change. Type in the connection command (first one on this blog, or press 'Up' twice on your keyboard), and you should connect as happy as you please.

Good luck, and happy server surfing to you!