skip to Main Content

How do I create a CloudFormation stack that automatically stands-up an EC2 linux instance but the login to be made via a password and without any keys.

I found a tutorial to enable password authentication but It requires changing the data in sshd_config and restarting the instance and I’m not sure how to replicate that in an cloudformation stack.

2

Answers


  1. I suggested by Mr. Paolo user-data is the way to go.

    Your final user-data script will look like this:

    #!/bin/bash
    yum update -y
    yum install -y httpd
    sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/g' /etc/ssh/sshd_config
    systemctl restart sshd
    

    This will make sure password auth is enabled once your system boots up and performs user data operations.

    Learn more about user data over this link:
    https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html

    Hope this helps. Thanks.

    Login or Signup to reply.
  2. I would do it differently… I would create a custom AMI first with password authentication, and then launch this ami as any other instance. Only in the unique situation when it is not possible, I would go with sed => restart route

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search