0

I have 2 instances in my Amazone ec2 console. Let it be Inst1 and Inst2 .

I created an image ( AMI ) for Inst2 and I launched that image as new instance with new key pair. But with that newly created I was not able to Login to the instance via ssh . So I stopped that instance .

But after that Inst1's key pair changed to that of Inst2. (means Inst1 and Inst2 now have the same key pair )

In amazon FAQ I checked, but in that they clearly mentioned that we can't chane the Key pair for an instance without stopping that instance. But in my case, Inst1's key pair got changed without restarting it and without my knowledge.

It is not fair to have the same key pair for both the instances. And Inst1 is a critical one and I can't stop that instance .

What should I do for this ?

How may be the key pair get changed ?

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
Sujith PS
  • 4,776
  • 3
  • 34
  • 61
  • When you say that the keypair changed, are you referring to the "name" of the keypair listed against the instance, or just the keypair used to login to the instance? (Given that a keypair can be overriden in the authorized_keys file.) – John Rotenstein Nov 26 '14 at 03:24
  • The Key-pair name got changed for that instance. – Sujith PS Nov 28 '14 at 05:03

1 Answers1

1

Keypairs are used to grant access to Amazon EC2 instances. They are public/private keypairs, typically randomly generated by EC2 but existing keypairs (or more specifically, the public half of the keypair) can be imported into EC2.

They are used as follows:

  • Windows: When starting Windows from a standard Windows AMI, a utility called Ec2Config randomly generates an Administrator password, encrypts it using the public half of the keypair, and passes it back through the System Log. Users must decrypt it using their private key. They can then login to Windows.
  • Linux: When starting Linux from a standard Linux AMI, the public half of the keypair is copied to .ssh/authorized_keys. Users can login via ssh by providing their private key.

(The reference to a 'standard' AMI is intentional -- AMIs created by other people will not necessarily have these utilities installed.)

In both situations, it is advisable that users then modify their instance to use their normal security standards. For example, Windows users should change the Administrator password or, preferably, attach the instance to an Active Directory domain. Linux users should create additional users and install their standard keypairs.

There should be no continuing need to use keypairs after the initial launch of the EC2 instance. Users should be using their own passwords/keypairs. It is not good practice to keep using the same password/keypair as initially created when the instance is launched.

To answer your question...

The keypair on an instance will not change (and in fact cannot change). The name of the keypair is listed as a property of the instance, so the keypair used can be identified.

However, Windows users can change the Administrator password and Linux users can replace the contents of the .ssh/authorized_keys file. Therefore, the password/keypair used to login to an instance might change, but the keypair listed against the instance (used during the first boot) does not change.

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470