0

I am having trouble to create a user and copy the corresponding pub file called authorized_keys into the .ssh folder on the instance using AWS Cloud Formation. I do this, because I want to connect with this user using SSH. When I check the SystemLog of the created instance, it does not seem like the user is created or any file is copied as authorized_keys in the .ssh directory, this is my code:

LinuxEC2Instance:
Type: AWS::EC2::Instance
Metadata:
  AWS::CloudFormation::Init:
    config:
      users:
        ansible:
          groups:
            - "exampleuser"
          uid: 1
          homeDir: "/home/exampleuser"
      files:
        /home/exampleuser/.ssh/authorized_keys:
          content: !Sub |
            '{{ resolve:secretsmanager:
              arn:aws:secretsmanager:availability-zone:account-id:secret:keyname:
                SecretString:
                  keystring }}'
          mode: "000600"
          owner: "exampleuser"
          group: "exampleuser"

Am I missing something so that the user is created and the file is also being copied?

Your Answer

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

Browse other questions tagged or ask your own question.