Creating and importing a Key pair using the OpenStack CLI

Using the OpenStack CLI, you can generate a new Key pair and import it an existing public key. This article assumes you've already installed the OpenStack CLI on your computer:

Creating a Key Pair and adding it to DreamCompute

To generate a key pair, run the following command.

[user@localhost]$ openstack keypair create KEY_NAME > MY_KEY.pem

This command generates a key pair using the names you specified and writes them to a .pem file. The Key Pair is then registered within your DreamCompute dashboard. You can view the list on the 'Compute > Key Pairs' page.

You can also view is my running the following command:

[user@localhost]$ openstack keypair list

Importing a previously existing Key Pair

If you have already generated a Key Pair on your Linux or Mac computer, the public key is most likely named 'id_rsa.pub' and located in the directory: ~/.ssh/id_rsa.pub. Run the following command to generate the new Key Pair in your DreamCompute dashboard.

The backslash character \ is used when entering a long command. When you enter the \, the terminal command continues to the next line until you finish entering it.

You could also remove the \ character and put every parameter into a single line.

[user@localhost]$ openstack keypair create --public-key \
~/.ssh/id_rsa.pub MY_KEY_NAME
+-------------+-------------------------------------------------+
| Field       | Value                                           |
+-------------+-------------------------------------------------+
| fingerprint | f2:fc:4f:ca:1c:b7:ba:43:1f:b8:e5:fc:63:84:79:13 |
| name        | My_KEY_NAME                                     |
| user_id     | 29815315c4ce4d48a27e767a63eb8320                |
+-------------+-------------------------------------------------+

The Key Pair is then registered within your DreamCompute dashboard. You can view the list on the 'Compute > Key Pairs' page.

It names the new Key Pair the name that you specify for MY_KEY_NAME. To ensure that the key pair has been successfully imported, run the following command to list key pairs:

[user@localhost]$ openstack keypair list

Did this article answer your questions?

Article last updated PST.