Use CLI to add SSH key pair to OpenStack

You can download this article in PDF format via the link below to support us.Download the guide in PDF formatClose

Use cli to add ssh key pair to Openstack: In this series of Openstack configuration and management, let us look at how to add ssh key pair to Openstack. This guide is based on the Openstack Ocata version.

The public/private key pair works by keeping the public key on the server and the private key on the local workstation. Once the server confirms that the two keys match, a secure connection can be established.

So, let’s generate a new ssh key pair, if there is already a pair, you can skip this pair:

$ ssh-keygen -t rsa -b 4096
Generating public/private rsa key pair.
Enter file in which to save the key (/home/josphat/.ssh/id_rsa): 
Created directory '/home/josphat/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/josphat/.ssh/id_rsa.
Your public key has been saved in /home/josphat/.ssh/
The key fingerprint is:
28:14:e0:14:11:0d:77:23:2d:6c:65:12:4e:26:a1:de [email protected]
The key's randomart image is:
+--[ RSA 4096]----+
| XXO+= |
| + *=*.. |
|. ..o. |
|. .. . |
| . E. . S |
| . |
| |
| |
| |

Copy the key to the clipboard:

xclip -sel clip < ~/.ssh/

Then log in to your Openstack controller node and save the key to a file:


Paste the key content into the file and save it.

The next step is to import the key using the openstack keypair command:

# openstack keypair create --public-key josphat
| Field       | Value                                           |
| fingerprint | 19:7b:5c:14:a2:21:7a:a3:dd:56:c6:e4:3a:22:e8:3f |
| name        | josphat                                         |
| user_id     | 93f0f5c4197f4f73b01bfe8086ecbec0                |

At last”Joseph“Is the name of the key pair seen on the Openstack command CLI and Horizon dashboard.


# openstack keypair list
| Name          | Fingerprint                                     |
| jmutai_pubkey | 19:7b:5c:14:a2:21:7a:a3:dd:56:c6:e4:3a:22:e8:3f |
| josphat       | 19:7b:5c:14:a2:21:7a:a3:dd:56:c6:e4:3a:22:e8:3f |

The same content can be confirmed on the Horizon dashboard by the following methods: Project>Key Pair:

OpenStack can inject the public ssh key into the instance at startup so that it can be accessed with the private key once it is ready. Go ahead and create a new VM, and upload the key pair:

openstack server create --flavor m1.tiny --image CoreOS-x86_64 
 --nic net-id=a54af9d4-d297-45b6-a98c-79d84add5f2e --security-group default 
 --key-name josphat coreos-test-vm

If you haven’t uploaded any images, I have provided detailed instructions on how to add images to Openstack, please check on the link below:

Add images to Openstack Glance

You can use the following methods to obtain the network ID, image name (ID) and security group:

# openstack image list
# openstack network list
# openstack security group list

Use CLI to add SSH key pair to OpenStack

Check whether the created instance is running and obtain its IP address:

openstack server list

Verify access rights:

$ ping -c 4 ip_address

You can now log in to the virtual machine in the following ways:

ssh [email protected]_address

Since I am using a CoreOS image, the default username is core

[email protected] ~ $ cat /etc/os-release 
NAME="Container Linux by CoreOS"
PRETTY_NAME="Container Linux by CoreOS 1409.8.0 (Ladybug)"

that’s it. More tutorials related to Openstack will be released soon. Follow us on Twitter for updates.

More articles:

How to add flavor to OpenStack using CLI

You can download this article in PDF format via the link below to support us.Download the guide in PDF formatClose