Setting up access to Amazon EC2 linux instance on a Mac

I recently got hold of a Macbook Pro, and since i’m planing on doing most of my JS and NodeJS development on this machine, one of the first things i needed to setup, was access to my AWS EC2 Linux instance, via the Terminal and via SFTP.

On my windows PC i spent about a day searching online for information about how to do on Windows, so i didn’t expect anything to be easy on my Mac, but it turned out to be a litle simpler this time around.
Getting access to the Linux instance via SSH

To get access to your Linux instance you’ll need your private key (.pem) (Guide to finding the private key) and you need to know the DNS name of you instance (Can be found on the AWS EC2 Console by clicking the instance)

Once you have these, you can make a small shell script that will open up the Terminal and connect you rigt into your linux instance. It’s done like this

Open up a text editor and paste in the following snippet

ssh -i /Path/To/PrivateKey.pem ec2-user@ec2-xx-xxx-xxx-xxx.eu-west-1.compute.amazonaws.com

ec2-user is the user that you log in with, in some linux distributions it might be root or something else.

ec2-xx-xxx-xxx-xxx.eu-west-1.compute.amazonaws.com is the public DNS name of your Linux instance, you should change this to your own dns name, or if you already have a domain name pointed to your linux instance, you can just use that instead.

Save the above script as ConnectToLinuxInstance.command.
The fileextension will tell OSX that the file should be opened by Terminal.app

The last thing you need to do is to allow the script to be executed, this is done with this command:
chmod +x ConnectToLinuxInstance.command

Double clicking ConnectToLinuxInstance.command now will open up the terminal and connect you straigt to your Linux instance.
Getting access to your site via SFTP

The next step you need is to setup a connection to the filesystem on your Linux Instance. I used Cyberduck for this, but any SFTP client that supports private keys should work.

To get this up and running you need the same information as above. The private key, and a public DNS name of your instance.

In Cyberduck you use the public DNS name as the server and ec2-user and your username, the last thing you do is tell the connection to use public key authenticaion and point to the location of your private key.
Once this is done, you should be able to connect to your instance.

If you found these tips useful, leave a comment or ask any questions you might have.
I’m still pretty new to SSH and *unix so i still have much to learn.


Comments: