Skip to content

Instantly share code, notes, and snippets.

@dungdt88
Created June 12, 2020 07:39
Show Gist options
  • Save dungdt88/276577dbc5071a04d3151b3c1f102ba2 to your computer and use it in GitHub Desktop.
Save dungdt88/276577dbc5071a04d3151b3c1f102ba2 to your computer and use it in GitHub Desktop.
AWS EC2 Cloud Init - Used when you lost key to ssh to your EC2 instance

Add this to your instance user data. You need to stop the instance before set this.

Content-Type: multipart/mixed; boundary="//"
MIME-Version: 1.0

--//
Content-Type: text/cloud-config; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="cloud-config.txt"

#cloud-config
cloud_final_modules:
- [users-groups, once]
users:
  - name: <username>
    shell: /bin/bash
    sudo:  ALL=(ALL) NOPASSWD:ALL
    ssh-authorized-keys: 
    - ssh-rsa <public-key-goes-here>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment