EC2

From Jonathan Gardner's Tech Wiki
Jump to: navigation, search

Getting the Public DNS

Click on your instance in the management console. You can see the public DNS below.

Login with SSH and PEM to EC2

I installed an ubuntu instance, so I have to login as 'ubuntu'. If you don't know what user to use, start with 'root'.

ssh -i <pem file> <user>@<public DNS>

You're in!

Convert .pem To SSH key

You really shouldn't do this. Store your .pem in a very, very safe place. It is the keys to the kingdom, so to speak.

Setting up your own account

Create the User

If you're root, you don't need to prefix the commands following with sudo. It probably won't hurt, though.

First, create a user account for yourself.

sudo useradd -s /bin/bash -m <your username>

(You can choose your favorite shell.)

Add the user to sudoers

Assuming you want sudo power, you'll need to add your user to the sudoers file or group.

sudo vim /etc/sudoers

Inspect this file. There is likely a group that has permissions. All you need to do is add your new users to that group.

sudo usermod -a -G <sudo group> <your username>

Otherwise, you can add a line specifically for your user to /etc/sudoers.

Set a password

You'll probably want a password, particularly since sudo will be asking your regular user for it.

passwd <your username>

Once this is set, you could login via SSH, if PasswordAuthentication is on. (It isn't, and shouldn't be, for a good reason.)

Initial login as the user

sudo su - <your username>

Now you are logged in as yourself.

SSH Keys

Now, you need to get your PUBLIC key up into your ~/.ssh/authorized_keys file. That file must also be set to the appropriate permissions (0600). Once that is done, you should be able to login easily.

Generate Your Keys

On your home machine, generate keys if you haven't already. You'll want to do this anyway, on every machine you have access to.

ssh-keygen -t dsa

If you don't choose a password, then you won't need to enter it to login. I suggest using a password, and then using ssh-add.

Move Your Public Key Up

On your home machine:

cat ~/.ssh/id_dsa.pub

(copy the key)

On the EC2 instance:

cat >> ~/.ssh/authorized_keys

(paste the key) (CTRL-D)

Be sure to set the permissions on authorized_keys to something reasonable:

chmod 600 ~/.ssh/authorized_keys