How to add new users to EC2 and give SSH Key access

July 21st, 2012

Here's how to add new users to an AMAZON EC2 linux instance and give them unique SSH Key access:

Say you are creating "user": Create a key on your own machine by entering the following:

  1. # ssh -keygen -b 1024 -f user -t dsa
  2. Don't use a paraphrase -- just hit enter.
  3. You should now have two files compiled: user and
  4. # chmod 600 Now transfer the public key file ( from your computer to the server. In this example, I use the /tmp/ directory.

Now SSH into your server using an account with root access, you will now need to create the user and also create the necessary files and ownership for you to use the key you just created:

  1. # sudo su (if needed)
  2. # useradd -c "firstname lastname" user
  3. # cd /home/user
  4. # mkdir .ssh
  5. # chmod 700 .ssh
  6. # chown user:user .ssh
  7. # cat /tmp/ >> .ssh/authorized_keys
  8. # chmod 600 .ssh/authorized_keys
  9. # chown user:user .ssh/authorized_keys

Once you've done this, exit out back to your own machine, then try to SSH using the new credential and user account you've created: # ssh -i user.pem Bam, you should be in!

Popular Posts