Creating a key pair
A key pair is used to access your instances via SSH. This is the quickest and easiest way to access your instances.
Â
Â
Getting ready
To perform this recipe, you must have your AWS CLI tool configured correctly.
How to do it...
- Create the key pair, and save it to disk:
aws ec2 create-key-pair \ --key-name MyEC2KeyPair \ --query 'KeyMaterial' \ --output text > ec2keypair.pem
- Change the permissions on the created file:
chmod 600 ec2keypair.pem
How it works...
This call requests a new private key from EC2. The response is then parsed using a JMESPath query, and the private key (in the KeyMaterial
property) is saved to a new key file with the .pem
extension.
Finally, we change the permissions on the key file so that it cannot be read by other users—this is required before SSH will allow you to use it.