Booting an Openstack instance with a defined username and password

Team evoila
16. October 2015
Reading time: 2 min

When booting a new instance on Openstack it is commonly missed the feature that lets us specify a username and a password (we who come from the rigid and complex world of the physical infrastructures and are arriving to the clouds are constantly complaining us about the lack of features on these environments which we consider “normal”). This option would be very useful when troubleshooting directly from the Horizon console but it can be a little bit insecure also (that`s why the preferred remote administration method in Openstack is the use of public key exchange).

A useful workaround for quick troubleshooting when booting a new instance is to add the username and password directly to the creation process. This is achieved by logging into Horizon`s dashboard, clicking on “Launch Instance” and adding the normal information on Details, Access & Security and Networking according to our own regular need. Then, on Post-Creation click “Direct Input” and inside the Script Data field add the following lines:


#!/bin/bash
addgroup NEWGROUP
useradd -g NEWGROUP -d /home/NEWUSER -s /bin/bash -p $(echo NEWPASSWORD | openssl passwd -1 -stdin) NEWUSER
adduser NEWUSER sudo

 

Replace NEWGROUP with an unique group name for your user, NEWUSER with the username and NEWPASSWORD with the desired password for that user. Note that the password must be given in md5 format but we are letting OpenSSL to do the job for us. The last step is to add the recently created user to the sudoers group so we can run tasks as root.

After booting, go directly to the instance console and log in with the given username/password.