Hello all,
It's been a while since my last post - hope you're all doing well😀
I often come across customers struggling with lost or misplaced SSH keys when dealing with their Veeam Backup for AWS appliances. To assist those in need, I've put together a simple guide on replacing the SSH key, particularly useful for regaining access to your Linux instances, whether they are Veeam Backup for AWS appliances or any other Linux-based systems.
Let's dive into the steps:
Step 1: Generate a New Key
Start by creating a new key using the AWS CLI with the following command:
aws ec2 create-key-pair --key-name MyReplacementKey --query ‘KeyMaterial’ --output text > MyReplacementKey.pem
Â
It will save the PEM file to the directory you are at when you run the command.
Remember to set the appropriate permissions for the key:
chmod 400 MyReplacementKey.pem
Now, generate the public key:
ssh-keygen -y -f MyReplacementKey.pem > MyPublicKey.pub
Step 2: Replace the Key
For this demonstration I launched an EC2 instance without a key:
On the terminal you will run the following AWS command:
aws ssm send-command --document-name AWS-RunShellScript --instance-ids i-09d134dae9acac5ad --parameters commands="touch /home/ec2-user/.ssh/authorized_keys && echo PASTE_PUB_CONTENT_HERE > /home/ec2-user/.ssh/authorized_keys",executionTimeout="3900"
Ensure to replace PASTE_PUB_CONTENT_HERE
with the content from the public key file.
Step 3: Connect with the New Key
After executing the command, you should now be able to connect to the Linux instance using the new key.
Â
Note: The key name on the AWS portal won't change. If it was initially missing, it will remain empty. If there was a previous name, it will persist. However, you can still connect seamlessly with the new key.
Â
The steps mentioned above can also be performed through the AWS Console. However, for the sake of simplicity and efficiency, on this guide I utilized the AWS CLI. The command-line approach tends to be quicker and more straightforward.
Feel free to choose the method that suits your preference or environment best.
Â
I hope this concise guide proves helpful. If you have any questions or run into issues, feel free to reach out.
Â