Skip to content

How to change login from root user to ec2 user in EC2 instance

0

I have 3 EC2 instances. One connects automatically with ec2 user and the other 2 automatically connects with root user. How can I change the root user to ec2 user for the 2 instances that automatically connect with the root user?

  • Hello buddy,

    The user by which we try to login is depends on ami we use.

    1. If you use Amazon linux then the default user will be ec2-user". You can login to instance using ec2-user and then switch to root user by entering cmd "sudo su"
    2. If you use Amazon linux then the default user will be "ubuntu". You can login to instance using "ubuntu" and then switch to root user by entering cmd "sudo su"

    If your copying the command to login to your instance then there might be a case sometimes aws gives you diff command. You can simply follow the command

    1. Amazon linux ssh -i name_of_keypair.pem ec2-user@public.ip.address.of.ec2

    2. Ubuntu ssh -i name_of_keypair.pem ubuntu@public.ip

    It's different with different linux distribution.

asked 2 years ago2.1K views

2 Answers
1

If you are connecting through instance connect - There is an option to change the default (available through the ami )user in the "Username" field.

If you are using ssm session manager - Refer to this - https://repost.aws/questions/QUpJoQ5PvBSYSzf_MkhmGv8g/how-can-i-changed-to-ec2-user-automatically-when-i-access-aws-linux-ec2-via-session-manager

If you want to change the user after logging in - sudo su - ec2-user should switch the user from root to ec2-user

AWS

answered 2 years ago

EXPERT

reviewed 2 years ago

EXPERT

reviewed 2 years ago

0

While the answers provided above are helpful, I highly recommend taking some time to review the following documentation. It will give you a deeper understanding of how system users work on EC2 instances and how you can connect to them effectively:

These resources will help you not only with your current issue but also with managing your EC2 users more efficiently in the future.

answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.