How to add new users to EC2 and give SSH Key access
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:
- # ssh -keygen -b 1024 -f user -t dsa
- Don't use a paraphrase -- just hit enter.
- You should now have two files compiled: user and user.pub
- # 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:
- # sudo su (if needed)
- # useradd -c "firstname lastname" user
- # cd /home/user
- # mkdir .ssh
- # chmod 700 .ssh
- # chown user:user .ssh
- # cat /tmp/user.pub >> .ssh/authorized_keys
- # chmod 600 .ssh/authorized_keys
- # 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 email@example.com Bam, you should be in!