Mastering EC2 User Management: A Comprehensive Guide

Mastering EC2 User Management: A Comprehensive Guide

Welcome to the world of AWS EC2 instances, where efficient user management is the key to unlocking the full potential of your cloud computing experience. In this blog, we'll dive deep into adding, deleting, and fine-tuning user accounts on your EC2 instances. Buckle up for a journey through the ins and outs of EC2 user management.

1. Create an EC2 instance

Our ec2 instance named "ubuntuinstance" has been created in the AWS cloud.

2. Connect to the ec2 instance via ssh

We are connected to our ec2 instance successfully.

Before creating a new user let's create a key pair named "ubuntu2-kp.pem" which will be used to generate the public key later. In the end, we will be able to log into the instance as a new user (ubuntu2) instead of the default user (ubuntu)

3. Add the new user in the ec2 instance

Verify the user

  1. Switch to the new user so that the directory and file that you create will have the proper ownership.

    The prompt changes from ubuntu to ubuntu2 to indicate that you have switched the shell session to the new user.

  2. Add the SSH public key to the user. First, create a directory in the user's home directory for the SSH key file, then create the key file, and finally paste the public key into the key file, as described in the following sub-steps.

a.Create a .ssh directory in the newuser home directory and change its file permissions to 700

b. Create a file named authorized_keys in the .ssh directory and change its file permissions to 600

c. Open the authorized_keys file using your favorite text editor and paste the public key

First, we need to generate the public key for the private key created earlier.We can see our public key generated here. We will copy this key and paste it to .ssh/authorized_keys

We pasted the public key that we generated earlier.

Now we should be able to log into the ubuntu2 user on the instance, using the private key that corresponds to the public key that we added to the authorized_keys file.

Hurray!! We are successfully logged in as a ubuntu2 user using the private key that we created separately.

Modifying User Permissions

Fine-tune a user's permissions by adjusting their group memberships and file permissions. For example, to change a file's owner:

Changing User's Group

Switching a user from one group to another is a breeze with the usermod command:

Here ubuntu user is added to ubuntu2 group.

Deleting a User

If the time comes to bid farewell to a user, use the userdel command:

In conclusion, each AWS professional must possess mastery of EC2 user management. You may create a safe and effective cloud computing environment by adding, removing, and modifying user accounts. To take control of your EC2 instance and improve your AWS experience, adhere to the following procedures and best practices. Cloud computing success!

Happy Learning!!