Search code examples
alibaba-cloudalibaba-cloud-ecs

Downloading existing key-pair (pem) file for ECS Instance Alibaba


I am working on a clients project and they have Magento installed on their EC2 instance, in order to ssh into it I need to have the pem file that was generated at the time of setting the key-pair. However I am not able to receive the pem file from their end and I am instead looking for a way to download the existing one. Is it even possible? Or do I create a new key-pair.


Solution

  • I wrote an article about Alibaba SSH Keypairs. If the keypair has been lost, you can replace it if you have Alibaba Cloud credentials (AccessKey and AccessKeySecret). This link to my article goes into specific details.

    Alibaba Cloud SSH & ECS KeyPairs

    The following commands require that the Alibaba Command Line CLI (aliyuncli) is installed and setup. I would backup (snapshot) the system before making the following changes.

    This command will create a new Keypair called "NewKeyPair"

    aliyuncli ecs CreateKeyPair --RegionId us-west-1 --KeyPairName NewKeyPair
    

    This command will replace the current keypair with NewKeyPair (Windows syntax).

    aliyuncli ecs AttachKeyPair --InstanceIds "[\"i-abcdeftvgllm854abcde\"]" --KeyPairName NewKeyPair