- Newest
- Most votes
- Most comments
Hi! When you created the AMI, did you remove the SSH host key pairs located in /etc/ssh? If you do so, this will force SSH to generate new and uique SSH key pairs when another instance is launched using the AMI (such as what you did in the Singapore region).
This includes the following key files that may be present:
- ssh_host_dsa_key
- ssh_host_dsa_key.pub
- ssh_host_key
- ssh_host_key.pub
- ssh_host_rsa_key
- ssh_host_rsa_key.pub
- ssh_host_ecdsa_key
- ssh_host_ecdsa_key.pub
- ssh_host_ed25519_key
- ssh_host_ed25519_key.pub
If you remove the SSH host key pairs prior to creating the AMI, then the shared AMI should use the new keys as you expected to happen. You can use something like shred to remove files: https://www.gnu.org/software/coreutils/manual/html_node/shred-invocation.html.
Edit: This is documented behavior. Check out the Remove SSH Key Pairs section of https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/building-shared-amis.html for a security practice to use when sharing AMIs. I would recommend removing the SSH key pairs when you're creating the image and this issue should resolve when you start a new instance from that new image.
This is expected behaviour.
In the console, key-pairs are region-specific - creating a key-pair in one region does not make it available in other regions. You can import key-pairs so that you have the same key-pair in each region; but creating a new key-pair in the Singapore region (even with the same name) is actually creating a new key-pair.
When you copied the AMI from N. Virginia to Singapore the AMI contained the public key for the key-pair from the N. Virginia region. Had you created a new AMI in the Singapore region it would have used the key material from the key-pair created in the Singapore region; but because it was copied it contained the original key material.
In the end, you got to a valid solution - taking the Singapore public key material and putting it on the instance; but you might also have created a key-pair and imported it into both regions: https://aws.amazon.com/premiumsupport/knowledge-center/ec2-ssh-key-pair-regions/
Relevant content
- asked 5 years ago
- AWS OFFICIALUpdated 2 months ago
- AWS OFFICIALUpdated 2 months ago
- AWS OFFICIALUpdated 5 months ago
- AWS OFFICIALUpdated 5 months ago
No, I didn't do anything out of the ordinary. I just stopped the instance and then started the image copy.