AWS Cloud

Connect to an Amazon EC2 instance without an original SSH key pair

kobo e reader

If you need to connect to an Amazon EC2 instance without an original SSH key pair on a new device, you can follow these steps:

  1. Create a new key pair or use existing key.
    • If you create a private key in the Amazon EC2 console, retrieve the public key of the key pair.
  2. Open the Amazon EC2 console.
  3. Stop the instance.
  4. Choose Actions, Instance Settings > Edit User Data.
  5. Copy the following script into the Edit User Data dialog box:
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"

- [users-groups, once]
  - name: username
    - ssh-rsa xxxxxxxxxxx (your public key)

Replace username with your username, such as ec2-user. You can enter the default username or a custom username (if previously set for the instance). For a list of default usernames, see Getting Instance-Related Information.

Replace PublicKeypair with the public key retrieved in step 2. Make sure to enter the entire public key, starting with ssh-rsa.

  1. Choose Save.
  2. Start your instance.
  3. After the cloud-init phase is complete, confirm that the public key has been replaced.

Important: Since the script contains a key pair, remove the script from the user data field.

  1. Stop the instance.
  2. Choose Actions, Instance Settings, Edit User Data.
  3. Delete all text in the Edit User Data dialog box, then choose Save.
  4. Start your instance.


%d 位部落客按了讚: