Create a virtual machine
This script creates an Azure Virtual Machine with an Ubuntu operating system and related networking resources. After running the script, you can access the virtual machine over SSH.
To run this sample, make sure you have installed the latest Azure CLI 2.0. To start, run
az login to create a connection with Azure.
This sample works in a Bash shell. For options on running Azure CLI scripts on Windows client, see Install the Azure CLI on Windows.
If you don't have an Azure subscription, create a free account before you begin.
#!/bin/bash # Create a resource group. az group create --name myResourceGroup --location westeurope # Create a new virtual machine, this creates SSH keys if not present. az vm create --resource-group myResourceGroup --name myVM --image UbuntuLTS --generate-ssh-keys
Clean up deployment
Run the following command to remove the resource group, VM, and all related resources.
az group delete --name myResourceGroup
This script uses the following commands to create a resource group, virtual machine, and all related resources. Each command in the table links to command specific documentation.
|az group create||Creates a resource group in which all resources are stored.|
|az vm create||Creates the virtual machine and connects it to the network card, virtual network, subnet, and network security group. This command also specifies the virtual machine image to be used and administrative credentials.|
|az group delete||Deletes a resource group including all nested resources.|
For more information on the Azure CLI, see Azure CLI documentation.
Additional virtual machine CLI script samples can be found in the Azure Linux VM documentation.