This section explains how to create a key pair to be used when logging in to a virtual server using SSH.
When registering the key pair, create the key file (*.pem), which is used for SSH authentication. You can use this key pair to log in to a virtual server.
Important: The key file should be managed with care.
-
Set the environment variable below as follows:
$ KEYPAIR=<keyPairName> (any)
$ AZ=<availabilityZoneName>
-
Execute the following API:
$ curl -X POST -Ss $COMPUTE/v2/$PROJECT_ID/os-keypairs \
-H "X-Auth-Token:$OS_AUTH_TOKEN" -H "Content-Type:application/json" \
-d '{"keypair": {"name": "'$KEYPAIR'", "availability_zone": "'$AZ'"}}' |\
jq -r .keypair.private_key > $KEYPAIR.pem
-
Enable the key file:
-
Display the content of the key file:
The following response is output:
-----BEGIN RSA PRIVATE KEY-----
~~omitted~~
-----END RSA PRIVATE KEY-----
-
Execute the following API to check the key pair that you created:
$ curl -X GET -Ss $COMPUTE/v2/$PROJECT_ID/os-keypairs \
-H "X-Auth-Token:$OS_AUTH_TOKEN" -H "Content-Type:application/json" \
| jq .
If a list including the key pair name that you specified is output, as follows, that means the key pair was created successfully.
{
"keypairs": [
...
{
"keypair": {
"public_key": "ssh-rsa
~~content omitted~~
== Generated by Nova\n",
"name": "<keyPairName>",
"fingerprint": "64:96:18:f9:f2:96:e9:7d:f2:b3:dd:ee:bc:45:eb:a0"
}
},
...
]
}
Tip: Apart from generating key pairs, it is also possible to import key pairs created externally.