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
title: 'Quickstart: Create a Linux VM and SSH into it'
3
-
description: Learn how to create a Linux virtual machine in Azure and SSH into it using Azure CLI commands within an Exec Doc.
2
+
title: Quickstart: Create a Linux VM and SSH into it using Azure CLI
3
+
description: Learn how to create a Linux virtual machine on Azure and connect to it using SSH with pre-generated SSH keys. This Exec Doc demonstrates deploying the VM in a uniquely named resource group, retrieving its public IP address, and providing the SSH command to connect.
In this Exec Doc, you will learn how to create a Linux virtual machine (VM) in Azure using the Azure CLI and then SSH into the newly created VM. All commands have been configured to run non-interactively. Remember to update any variables if necessary and note that resources are appended with a random suffix to avoid naming conflicts in subsequent runs.
11
+
# Quickstart: Create a Linux VM and SSH into it using Azure CLI
12
12
13
-
## Step 1: Set Environment Variables
13
+
This Exec Doc walks you through deploying a Linux virtual machine (VM) on Azure using the Azure CLI. The VM is deployed in a new resource group with a random suffix to ensure uniqueness. Once the VM is created, the public IP is retrieved and an SSH command is provided so you can connect to the VM.
14
14
15
-
In this step, we declare the environment variables that will be used throughout the Exec Doc. A random suffix is appended to the resource group and VM names to ensure uniqueness.
15
+
## Step 1: Set Environment Variables and Create a Resource Group
16
+
17
+
In this step, we declare environment variables that will be used throughout the Exec Doc. We generate random suffixes to ensure that resource names are unique between successive runs.
Now you will create a Linux VM using the Ubuntu LTS image. The command includes the generation of SSH keys if they do not already exist. The default administrator username is set to "azureuser".
50
+
Now that the resource group is ready, we create a Linux VM. In this example, the VM is created with an Ubuntu 22.04 image, which is a valid image name. A default administrator username is provided and SSH keys are generated automatically if they do not exist in your environment.
53
51
54
52
```bash
55
-
az vm create --resource-group $MY_RESOURCE_GROUP_NAME --name $MY_VM_NAME --image UbuntuLTS --admin-username azureuser --generate-ssh-keys
53
+
export VM_NAME="LinuxVm$RANDOM_SUFFIX"
54
+
az vm create --resource-group $RESOURCE_GROUP --name $VM_NAME --image Ubuntu2204 --admin-username azureuser --generate-ssh-keys
Next, you retrieve the public IP address of the newly created VM. This value is stored in an environment variable for later use in the SSH command.
76
+
After the VM is created, we need its public IP address to connect via SSH. The following command queries the public IP address from the VM's network settings and stores it in an environment variable.
77
77
78
78
```bash
79
-
export PUBLIC_IP=$(az vm show -d --resource-group $MY_RESOURCE_GROUP_NAME --name $MY_VM_NAME --query publicIps -o tsv)
Finally, use the SSH command to connect to your Linux VM. The SSH command includes the option to disable strict host key checking to avoid interactive prompts during the first connection.
85
+
<!-- expected_similarity=0.3 -->
86
+
```text
87
+
The public IP of the VM is: xx.xx.xx.xx
88
+
```
89
+
90
+
## Step 4: SSH into the Linux VM
91
+
92
+
Now that you have the public IP, the following SSH command is provided for informational purposes. When executed, it will open an interactive SSH session into the Linux VM.
This SSH command connects you to the VM using the default administrator account "azureuser". Once connected, you can start managing your Linux environment directly.
91
-
92
-
Happy learning and exploring your new Linux VM in Azure!
98
+
This completes the Exec Doc for deploying a Linux VM and connecting to it via SSH using the Azure CLI.
0 commit comments