-2

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.
  • That's very unclear what you're doing, mind to share more of your script/user creation process and where the line is ? – Tensibai Jul 2 '18 at 8:29
  • 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 Jul 2 '18 at 9:46
  • 1
    I'm sorry but I really don't get it, please edit your question with more details. – Tensibai Jul 2 '18 at 10:01
  • i have edited my question Please check it – MeetGadhiya Jul 2 '18 at 10:02
  • 3
    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 Jul 2 '18 at 10:17
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.