Create a VM from the CLI
This page creates a VM from scratch with openstack. The same flow maps to the API calls in Create VM, but the CLI fills in the request body for you.
1. Find the resources
openstack flavor list
openstack image list
openstack network list
openstack security group list
Keep the IDs. Names are not unique across projects, so pass IDs in scripts.
For the external network used by floating IPs:
openstack network list --external
2. Add an SSH key
openstack keypair create --public-key ~/.ssh/id_ed25519.pub mykey
openstack keypair list
If the key pair already exists, skip this step and reuse its name.
3. Allow SSH
The default security group blocks inbound traffic. Create a rule scoped to your own address:
openstack security group rule create \
--proto tcp \
--dst-port 22 \
--remote-ip 203.0.113.10/32 \
default
For a quick test only, 0.0.0.0/0 works, but do not leave SSH open to the internet.
4. Create the VM
openstack server create \
--flavor <flavor-id> \
--image <image-id> \
--network <network-id> \
--key-name mykey \
--security-group default \
vm1
The command returns immediately. The VM goes through BUILD and then ACTIVE:
openstack server show vm1 -f json
openstack server list --name vm1
5. Boot from a volume
Use a volume when you need a specific volume type, a larger disk than the flavor, or a volume that survives the VM.
openstack volume create \
--image <image-id> \
--size 20 \
--type nvmer3 \
vm1-root
openstack server create \
--flavor <flavor-id> \
--volume vm1-root \
--network <network-id> \
--key-name mykey \
--security-group default \
vm1
--volume takes an existing volume. Do not pass --image in the same command.
6. Add a floating IP
openstack floating ip create <external-network-id>
openstack server add floating ip vm1 <floating-ip-address>
openstack server show vm1 -c addresses -f json
Then connect:
ssh -i ~/.ssh/id_ed25519 <image-user>@<floating-ip-address>
The login user depends on the image, for example ubuntu, rocky, fedora, or cloud-user.
7. Clean up
openstack server delete vm1
openstack floating ip delete <floating-ip-address>
A volume created for the VM is not deleted with it. Delete it separately if you no longer need it:
openstack volume delete vm1-root