Creating multiple users for an EC2 Instance on AWS

@loveagileqa

qualityworkscg.com

Creating multiple Users for EC2 Instance on AWS

Users

2

...

3

1

Creating multiple Users for your EC2 Instance on AWS

Generate Public & Private Keys for Users

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.

Generate Public & Private Keys for Users

Creating multiple Users for EC2 Instance on AWS

P

ublic

rivate

Keys for AWS Users

Creating multiple Users for EC2 Instance on AWS

Public & Private Keys for 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.

Public & Private Keys for Users

Public & Private Keys for Users

$ 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.

Public & Private Keys for Users

$ 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.

Public & Private Keys for Users

screenshot showing scp from local machine

screenshots showing commands ran on EC2 instance from the 2 previous pages.

Public & Private Keys for Users

$ 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.

Public & Private Keys for Users

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.

Made with Slides.com