Essentially there is always a few steps to follow in order to easy SSH in to your AWS server without the need for your .pem key. For security reasons, this is not an option when you first setup a server, but with these few instructions, right when you setup your server can save you a lot of irritation always hunting down the correct .pem key.
- Must have an AWS Account
- Must have a way to use commands line. (PuTTY is an option for windows)
- EC2 Server (Click here you need help launching a EC2 on Amazon
Part 1: Generate a id_rsa.pub
id_rsa.pub if you have not done so already. Here are the steps needed for that.
- We need to navigate where we typically keep our system ssh key, in command line:
$ cd ~/.ssh
- Next, we will generate a key with our email address.
$ ssh-keygen -t rsa -C "firstname.lastname@example.org"
It will ask you a few questions, you can just hit “Enter”.
- Then type
$ ls -l
This will list out all of the files, it will look something like this:
- Next we need to copy our .pub key to our clipboard so we can post it in Github. Run:
$ pbcopy < id_rsa.pub
You can find more details if needed about id_rsa.pub here.
Part 2: Login to your EC2 Server and Add your Key
We are going to SSH into our current server and then add our key to your server so we do not have to use .pem any more to login.
- First lets, login to our AWS console.
- Next, we will select EC2 and then click on instances. With your instance selected, click on one of the servers and hit connect. It will launch a dialog box with your connection string in there. It should look something like this:
- Now grab your connection string and goto command line and past it in. Ex:
$ ssh -i erickey.pem email@example.com
- Once you're connected to your server, you will need so login into the root user. You will be able to do this by using:
$ sudo su
- Next we will
cdinto our directory with our authorized_keys to add th id_rsa.pub that we have copied to our clipboard. Run:
$ cd ~/.ssh
Here you will see a file called
- We need to modify this file by adding our key. Run:
$ nano authorized_keys
and paste your key into the file under the default key at the top. To exit out of the file, hit
ctrl+xand then hit
yto save the file.
Now you will be able to exit your server and log back in as root just by using
$ ssh firstname.lastname@example.org
This makes life a lot easier, so you don't have to hunt down that pesky .pem file and where you put it.