AMPEDUPDESIGNS

CONSULTING CONCEPTS PERSONAL

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 user.pub
  4. # chmod 600 user.pub Now transfer the public key file (user.pub) 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/user.pub >> .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 user@ec2-your-instance-name.compute-1.amazonaws.com Bam, you should be in!



Popular Posts