Lost access to openstack server

Maybe you have switched machines, and no longer have a private key available. In this case, if you have the api key available, you can generate a new keypair to login to your instance.

openstack client configuration and installation

Use apt or another packet manager for your system to install the openstack client

apt install python-openstackclient

non root installation of openstack client

pip install --user python-openstackclient

I got dependencies problems, --user did not work, I solved it with a python virtual environment

pip install --user virtualenv
# Make a new virtual environment
virtualenv --no-site-packages openstack_venv
cd openstack_venv
# enter/activate new environment, pip list should return very few packages now
source ./bin/activate
pip install python-openstackclient

I followed this guide, to configure the client

export [email protected]
export OS_PROJECT_NAME=DEMO-gregorjt.ifi.uio.no
export OS_PASSWORD=<api_key_here>
export OS_AUTH_URL=https://api.uh-iaas.no:5000/v3
export OS_IDENTITY_API_VERSION=3
export OS_USER_DOMAIN_NAME=dataporten
export OS_PROJECT_DOMAIN_NAME=dataporten
export OS_REGION_NAME=osl
export OS_NO_CACHE=1

just google openstack client environment variables to get more general examples

Remember to source the file you put the exports into.

Generate a new keypair

# Check if you have configured everything right, should output your servers
$ openstack server list 

The output should look something like this:

root@scw-2c3792:~# openstack server list
+--------------------------------------+--------+--------+------------------------------------------------+
| ID                                   | Name   | Status | Networks                                       |
+--------------------------------------+--------+--------+------------------------------------------------+
| 32e8e0aa-1c6e-4990-9465-9b74c2f32101 | ubuntu | ACTIVE | dualStack=158.39.75.148, 2001:700:2:8200::2033 |
+--------------------------------------+--------+--------+------------------------------------------------+

Then, a keypair can be generated according to the documentation:

$ openstack keypair create <name_of_key>

This should give you a private key which you can put in ~/.ssh/<my_file_name>

$ openstack keypair list

Output:

root@scw-2c3792:~# openstack keypair list
+--------------+-------------------------------------------------+
| Name         | Fingerprint                                     |
+--------------+-------------------------------------------------+
| uio_priv_key | ef:80:90:84:31:21:c6:ec:33:b9:37:b0:38:76:52:b6 |
+--------------+-------------------------------------------------+

ssh into the server should now work, the ip is available in the openstack server list output