<p>The users who are present in a newly launched EC2 instance are the ones that exist in the image you launch it from.</p>
<p>The images provided by the Linux distros tend to have only one default user, but you can build your own custom image with other users, and launch your EC2 servers from your image/images.</p>
<p>And there's cloud-init config that can create a user at launch time, too (as a comment pointed out already).</p>

CC BY-SA 4.0
2022-08-16T00:59:17.627Z
2022-08-16T00:59:17.627Z
Sotto Voce
<ol>
<li><p>After launching a EC2 instance, do I have to always log into the instance for the first time, by SSH with the default user for the image of the instance?
Or is it possible to first time log into a new instance, by a user not the default one?</p>
</li>
<li><p>When launching a EC2 instance using either AWS CLI2 or Terraform,
is it possible to specify a user to create and its authentication method (by specifying a EC2 private/public key pair created for AWS already), so that I will have a non-default user to log into the instance for the first time? Or creating a non-default user for a new instance can only be done under the default user's login session?</p>
</li>
</ol>
<p>Thanks.</p>

CC BY-SA 4.0
2022-08-14T23:47:27.567Z
You should be able to provide a [user-data configuration](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html) to your Ec2 instance that instructs [cloud-init](https://cloudinit.readthedocs.io/en/latest/) to configure a non-default user.
larsks
<terraform><amazon-ec2>
Is it possible to log into a new EC2 instance for the first time using a non-default user?
Tim
# Is it possible to log into a new EC2 instance for the first time using a non-default user?

(Asked by: username_0 on 2022-08-14)

1. After launching a EC2 instance, do I have to always log into the instance for the first time, by SSH with the default user for the image of the instance?
   Or is it possible to first time log into a new instance, by a user not the default one?
2. When launching a EC2 instance using either AWS CLI2 or Terraform,
   is it possible to specify a user to create and its authentication method (by specifying a EC2 private/public key pair created for AWS already), so that I will have a non-default user to log into the instance for the first time? Or creating a non-default user for a new instance can only be done under the default user's login session?

Thanks.

**Tags:** terraform, amazon-ec2

> **Comments:**
> **username_1**: You should be able to provide a [user-data configuration](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html) to your Ec2 instance that instructs [cloud-init](https://cloudinit.readthedocs.io/en/latest/) to configure a non-default user.  

---

## 1 answers

### Answer by username_2 on 2022-08-16. Score: 2

The users who are present in a newly launched EC2 instance are the ones that exist in the image you launch it from.

The images provided by the Linux distros tend to have only one default user, but you can build your own custom image with other users, and launch your EC2 servers from your image/images.

And there's cloud-init config that can create a user at launch time, too (as a comment pointed out already).


---

