QualityWorks
QualityWorks Consulting Group is Southern California’s premier consulting firm for software quality innovation. Established in 2009, QualityWorks has had successful engagements throughout Southern California.
Creating multiple users for an EC2 Instance on AWS
@loveagileqa
qualityworkscg.com
Creating multiple Users for your EC2 Instance on AWS
Create Users on EC2 Instance.
After you access your AWS Instance via ssh
$ sudo adduser <username> to add user.
$ sudo su to switch to the root user.
$ passwd <username> to add a password for that user.
Now add the user to sudoer’s list by running $ visudo press enter, search for [root ALL = (ALL) ALL] and add [<username> ALL = (ALL) ALL] below it. (see screenshot on next page).
Create Users on EC2 Instance.
Switch & modify Users on EC2 Instance.
$ su <username> to switch to the user you just created.
n.b. If you mess up $ sudo userdel -rf <username> to delete user.
Thats it!
Now let's head on over to the right and Generate Public & Private keys for our new Users.
ublic
rivate
Keys for AWS Users
$ cd /home/<username>/ to switch to the user directory.
$ ssh-keygen -b 4096 -f <username> -t rsa to generate keys.
$ mkdir .ssh to make a .ssh folder inside the user folder.
$ chmod 700 .ssh so that the owner of the file can read, write and execute.
$ cat <username>.pub > .ssh/authorized_keys to store public key in authorized keys file.
$ chmod 600 .ssh/authorized_keys so that the owner can read and write to the file.
$ sudo chown <username>:ec2-user .ssh to set the owner to <username> and the group onwer is ec2-user.
$ sudo chown <username>:ec2-user .ssh/authorized_keys to set the owner to <username> and the group owner is ec2-user.
$ sudo cp <username> /home/ec2-user/ OR $ sudo rsync -avr <username> /home/ec2-user/ to copy user.
$ sudo chmod 777 /home/ec2-user/<username> so that all can read, write and execute.
Using your local terminal
$ scp -i <your_key.pem> ec2-user@<yourElasticIP>:/home/ec2-user/<username> <username> to copy the key “<username>” your AWS Server.
screenshot showing scp from local machine
screenshots showing commands ran on EC2 instance from the 2 previous pages.
$ chmod 400 <username> so that owner can read.
You will get a prompt to enter the password for the key you created.
$ ssh -i <key_just_created> <username>@<yourElasticIP> to access your AWS Server.
This key that you have created, you can now give that to the person that you want to access your instance.
If you added a password on your key like I did, you would also need to give your user that password as well.
Congratulations!
You have now successfully learnt how to create users for your EC2 Instance that can connect securely via ssh.
Learn how to install MongoDB on your EC2 instance.
By QualityWorks
This tutorial will explain how to create public & private keys to allow users to SSH into your Elastic Compute Cloud (EC2) instance created in the previous tutorial.
QualityWorks Consulting Group is Southern California’s premier consulting firm for software quality innovation. Established in 2009, QualityWorks has had successful engagements throughout Southern California.