<p>Terraform is awesome for setting everything up. I like it less for the actual configuration.
After Terraform runs and sets everyhting up (ec2 security groups/instances etc,.) we run Ansible to configure additional users.</p>

<p>I recommend leaving AWS default user (ec2user, ubuntu) if you're using SSH Keys. Add to your 'authorized keys' all the public keys for users you want to allow ssh access. remember to edit 'sudoers' and create groups as needed.
try separating users into groups and in 'sshd_config' allow the groups to connect via ssh. (each member of the group needs to have his public key in 'authorized keys')</p>

<p>restart sshd and you're good.</p>

CC BY-SA 4.0
2018-07-03T06:03:18.957Z
2018-07-03T06:03:18.957Z
Asaph
<p>I have a lot of instance in aws.I have build through terraform. I have made scripts of making user(e.g. <strong>user1</strong> rather than <strong>ec2-user</strong>).But i am facing one issue.when i check .ssh/authorized_key. I have seen this line <strong>Please login as the user "ec2-user" rather than the user "root"</strong>.The problem is that whenever i login using this user(like user1@XXXXXXX) get this msg and denied to login but i have remove this line and try then it's working.but i want to remove this line not manually. How can i do?in this scripts i have done few steps.</p>

<ul>
<li>sudo adduser user1</li>
<li>usermod -a -G sudo user1</li>
<li>cp ~/.ssh/authorized_key /home/user1/.ssh/authorized_keys
After this i am trying to login through ssh user1@XXXXX-XXXX and then show me this line on terminal <strong>Please login as the user "ec2-user" rather than the user "root"</strong>.So i have entered through ec2-user@XXXX-XXXX and then i have switched user to user1 from ec2-user.and then remove this line <strong>Please login as the user "ec2-user" rather than the user "root"</strong> because this line is by default come.after that i have easily login through user1@XXXXXX-XXXX but how can i configured without showing this line msg.</li>
</ul>

CC BY-SA 4.0
2018-07-02T08:29:11.137Z
That's very unclear what you're doing, mind to share more of your script/user creation process and where the line is ?
Tensibai
CC BY-SA 4.0
2018-07-02T09:46:34.563Z
i have a scripts that making a user(let's say user1).when we launch aws instance,by default ec2-user will be launched.So i have run the scripts in terraform
MeetGadhiya
CC BY-SA 4.0
2018-07-02T10:01:17.290Z
I'm sorry but I really don't get it, please [edit] your question with more details.
Tensibai
CC BY-SA 4.0
2018-07-02T10:02:28.670Z
i have edited my question Please check it
MeetGadhiya
CC BY-SA 4.0
2018-07-02T10:17:38.527Z
You're copying root's authorized_keys file with this cp in the instance userdata, copy ec2-user's one and you'll be good without this warning line. I.e: `cp /home/ec2-user/.ssh/authorized_keys /home/user1/.ssh/authorized_keys`. There's still permissions problems after that. BTW this sounds kinda useless to create just another user with the same key... this sounds like a XY problem adding complexity and attack surface for no purpose.
Tensibai
<terraform><linux><shell-script>
Set user in aws
MeetGadhiya
# Set user in aws

(Asked by: username_0 on 2018-07-02)

I have a lot of instance in aws.I have build through terraform. I have made scripts of making user(e.g. **user1** rather than **ec2-user**).But i am facing one issue.when i check .ssh/authorized\_key. I have seen this line **Please login as the user "ec2-user" rather than the user "root"**.The problem is that whenever i login using this user(like user1@XXXXXXX) get this msg and denied to login but i have remove this line and try then it's working.but i want to remove this line not manually. How can i do?in this scripts i have done few steps.

* sudo adduser user1
* usermod -a -G sudo user1
* cp ~/.ssh/authorized\_key /home/user1/.ssh/authorized\_keys
  After this i am trying to login through ssh user1@XXXXX-XXXX and then show me this line on terminal **Please login as the user "ec2-user" rather than the user "root"**.So i have entered through ec2-user@XXXX-XXXX and then i have switched user to user1 from ec2-user.and then remove this line **Please login as the user "ec2-user" rather than the user "root"** because this line is by default come.after that i have easily login through user1@XXXXXX-XXXX but how can i configured without showing this line msg.

**Tags:** terraform, linux, shell-script

> **Comments:**
> **username_1**: That's very unclear what you're doing, mind to share more of your script/user creation process and where the line is ?  
> **username_0**: i have a scripts that making a user(let's say user1).when we launch aws instance,by default ec2-user will be launched.So i have run the scripts in terraform  
> **username_1**: I'm sorry but I really don't get it, please [edit] your question with more details.  
> **username_0**: i have edited my question Please check it  
> **username_1**: You're copying root's authorized_keys file with this cp in the instance userdata, copy ec2-user's one and you'll be good without this warning line. I.e: `cp /home/ec2-user/.ssh/authorized_keys /home/user1/.ssh/authorized_keys`. There's still permissions problems after that. BTW this sounds kinda useless to create just another user with the same key... this sounds like a XY problem adding complexity and attack surface for no purpose.  

---

## 1 answers

### Answer by username_2 on 2018-07-03. Score: 1

Terraform is awesome for setting everything up. I like it less for the actual configuration.
After Terraform runs and sets everyhting up (ec2 security groups/instances etc,.) we run Ansible to configure additional users.

I recommend leaving AWS default user (ec2user, ubuntu) if you're using SSH Keys. Add to your 'authorized keys' all the public keys for users you want to allow ssh access. remember to edit 'sudoers' and create groups as needed.
try separating users into groups and in 'sshd\_config' allow the groups to connect via ssh. (each member of the group needs to have his public key in 'authorized keys')

restart sshd and you're good.


---

