AWS CLI: Key is not in valid OpenSSH public key format

amazon-ec2, amazon-web-services, aws-cli

Solution

Create your key and then when calling aws's `--public-key-material` argument, call it with `file://` in front of your key path.

Example:

$ aws --region eu-central-1 ec2 import-key-pair \
    --key-name "awsfrankfurt" \
    --public-key-material file://~/.ssh/awsfrankfurt  # <-- this

This is a weird issue, because, `file://` prefix is usually used for Windows, but, here with aws, it applies to unix based terminals as well.

Problem

How to solve this? ``` # I used this command to create the key with a password $ ssh-keygen -b 2048 -t rsa -C "awsfrankfurt" -f ~/.ssh/awsfrankfurt # Then when I try to import it into AWS EC2, the error appears: $ aws --region eu-central-1 ec2 import-key-pair \ --key-name "awsfrankfurt" \ --public-key-material ~/.ssh/awsfrankfurt An error occurred (InvalidKey.Format) when the ImportKeyPair operation: Key is not in valid OpenSSH public key format ```

Original source