You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Quickstart: Create a Linux virtual machine with the Azure CLI on Azure
15
+
16
+
**Applies to:**:heavy_check_mark: Linux VMs
15
17
16
18
[](https://portal.azure.com/?Microsoft_Azure_CloudNative_clientoptimizations=false&feature.canmodifyextensions=true#view/Microsoft_Azure_CloudNative/SubscriptionSelectionPage.ReactView/tutorialKey/CreateLinuxVMAndSSH)
17
19
20
+
This quickstart shows you how to use the Azure CLI to deploy a Linux virtual machine (VM) in Azure. The Azure CLI is used to create and manage Azure resources via either the command line or scripts.
21
+
22
+
If you don't have an Azure subscription, create a [free account](https://azure.microsoft.com/free/?WT.mc_id=A261C142F) before you begin.
23
+
24
+
## Launch Azure Cloud Shell
25
+
26
+
The Azure Cloud Shell is a free interactive shell that you can use to run the steps in this article. It has common Azure tools preinstalled and configured to use with your account.
27
+
28
+
To open the Cloud Shell, just select **Try it** from the upper right corner of a code block. You can also open Cloud Shell in a separate browser tab by going to [https://shell.azure.com/bash](https://shell.azure.com/bash). Select **Copy** to copy the blocks of code, paste it into the Cloud Shell, and select **Enter** to run it.
29
+
30
+
If you prefer to install and use the CLI locally, this quickstart requires Azure CLI version 2.0.30 or later. Run `az --version` to find the version. If you need to install or upgrade, see [Install Azure CLI](/cli/azure/install-azure-cli).
31
+
18
32
## Define environment variables
19
33
20
-
The First step is to define the environment variables.
34
+
The first step is to define the environment variables. Environment variables are commonly used in Linux to centralize configuration data to improve consistency and maintainability of the system. Create the following environment variables to specify the names of resources that you create later in this tutorial:
In order to run commands in Azure using the CLI, you need to log in first. This is done using the `az login` command.
47
+
In order to run commands in Azure using the CLI, you need to log in first. Log in using the `az login` command.
34
48
35
49
## Create a resource group
36
50
37
-
A resource group is a container for related resources. All resources must be placed in a resource group. The following command creates a resource group with the previously defined $MY_RESOURCE_GROUP_NAME and $REGION parameters.
51
+
A resource group is a container for related resources. All resources must be placed in a resource group. The [az group create](/cli/azure/group) command creates a resource group with the previously defined $MY_RESOURCE_GROUP_NAME and $REGION parameters.
38
52
39
53
```bash
40
54
az group create --name $MY_RESOURCE_GROUP_NAME --location $REGION
@@ -59,7 +73,9 @@ Results:
59
73
60
74
## Create the virtual machine
61
75
62
-
To create a VM in this resource group, we need to use the `vm create` command. In the following code example, we provided the `--generate-ssh-keys` flag, which causes the CLI to look for an available ssh key in `~/.ssh`. If one is found, it is used. If not, one is generated and stored in `~/.ssh`. We also provide the `--public-ip-sku Standard` flag to ensure that the machine is accessible via a public IP address. Finally, we deploy the latest `Ubuntu 22.04` image.
76
+
To create a VM in this resource group, use the `vm create` command.
77
+
78
+
The following example creates a VM and adds a user account. The `--generate-ssh-keys` parameter causes the CLI to look for an available ssh key in `~/.ssh`. If one is found, that key is used. If not, one is generated and stored in `~/.ssh`. The `--public-ip-sku Standard` parameter ensures that the machine is accessible via a public IP address. Finally, we deploy the latest `Ubuntu 22.04` image.
63
79
64
80
All other values are configured using environment variables.
65
81
@@ -74,7 +90,7 @@ az vm create \
74
90
--public-ip-sku Standard
75
91
```
76
92
77
-
Results:
93
+
It takes a few minutes to create the VM and supporting resources. The following example output shows the VM create operation was successful.
78
94
79
95
<!-- expected_similarity=0.3 -->
80
96
```json
@@ -105,7 +121,7 @@ az vm extension set \
105
121
106
122
## Store IP address of VM in order to SSH
107
123
108
-
Run the following command to store the IP Address of the VM as an environment variable:
124
+
Run the following command to store the IP address of the VM as an environment variable:
109
125
110
126
```bash
111
127
export IP_ADDRESS=$(az vm show --show-details --resource-group $MY_RESOURCE_GROUP_NAME --name $MY_VM_NAME --query publicIps --output tsv)
0 commit comments