Thursday, November 8, 2012

[Tutorial] How to SSH into Amazon EC2 Server


Amazon AWS is relatively new web service but its been growing rapidly since its initial launch.
They have thousands of large clients including banks and federal government.
I have recently started using their services for a start-up I am working on.

Amazon AWS EC2 server is set up little different than other common servers in a sense that it only allows access through a private key. Upon creation of Amazon AWS EC2 Server you will receive private key.
It is important to have this key saved somewhere secure and NEVER LOSE IT!!! or else you are going to have bad time.

Requires Private Key

Simply accessing the server over SSH will give you Permission Denied (public key) error.

 ssh root@your-ip

You need to use your private key to access.

 ssh -i your-key.pem your-ip

Requires Permission Change

If you get following error:

 It is required that your private key files are NOT accessible by others.
  This private key will be ignored.

This means your private key is not protected and you need to change the permission.

 chmod 400 your-key.pem

Know your user

If you will still see Permission Denied (public key) error, it is very likely that you have wrong user.
Depending on your linux distribution, you probably wont be able to log in with root.
For Ubuntu distribution available in AWS repository, the default user is "ubuntu"

 ssh -v -l ubuntu -i your-key.pem your-ip

There you go! You should be able to log into your server now.

No comments: