Skip to content

Commit fcea4bc

Browse files
authored
Merge pull request #17567 from naman-msft/docs-editor/azure-stack-quick-create-vm-li-1744004060
Update azure-stack-quick-create-vm-linux-cli.md
2 parents ae491a0 + 3960afa commit fcea4bc

File tree

1 file changed

+112
-36
lines changed

1 file changed

+112
-36
lines changed

azure-stack/user/azure-stack-quick-create-vm-linux-cli.md

Lines changed: 112 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,11 @@ title: Create Linux VM with Azure CLI in Azure Stack Hub
33
description: Create a Linux virtual machine by using the Azure CLI in Azure Stack Hub.
44
author: sethmanheim
55
ms.topic: quickstart
6-
ms.date: 03/06/2025
6+
ms.date: 04/06/2025
77
ms.author: sethm
8-
9-
# Intent: As an Azure Stack user, I want to create a Linux server virtual machine using Azure CLI.
10-
# Keyword: linux virtual machine CLI
118
ms.custom: mode-api, devx-track-azurecli, linux-related-content
129
---
1310

14-
1511
# Quickstart: Create a Linux server VM by using the Azure CLI in Azure Stack Hub
1612

1713
You can create an Ubuntu Server 20.04 LTS virtual machine (VM) by using the Azure CLI. In this article, you create and use a virtual machine. This article also shows you how to:
@@ -30,7 +26,7 @@ Before you begin, make sure you have the following prerequisites:
3026

3127
* Azure Stack Hub requires a specific version of the Azure CLI to create and manage its resources. If you don't have the Azure CLI configured for Azure Stack Hub, sign in to a Windows-based external client if you're connected through VPN, and follow the instructions for [installing and configuring the Azure CLI](azure-stack-version-profiles-azurecli2.md).
3228

33-
* A public Secure Shell (SSH) key with the name `id_rsa.pub` saved in the **.ssh** directory of your Windows user profile. For more information about creating SSH keys, see [Use an SSH key pair with Azure Stack Hub](azure-stack-dev-start-howto-ssh-public-key.md).
29+
* A public Secure Shell (SSH) key with the name **id_rsa.pub** saved in the **.ssh** directory of your Windows user profile. For more information about creating SSH keys, see [Use an SSH key pair with Azure Stack Hub](azure-stack-dev-start-howto-ssh-public-key.md).
3430

3531
## Create a resource group
3632

@@ -39,24 +35,66 @@ A resource group is a logical container where you can deploy and manage Azure St
3935
> [!NOTE]
4036
> We assigned values for all variables in the following code examples. However, you can assign your own values.
4137
42-
The following example creates a resource group named myResourceGroup in the local location:
38+
The following example creates a resource group named myResourceGroup with a random suffix in the local location:
4339

4440
```azurecli
45-
az group create --name myResourceGroup --location local
41+
export RANDOM_SUFFIX=$(openssl rand -hex 3)
42+
export RESOURCE_GROUP="myResourceGroup$RANDOM_SUFFIX"
43+
export LOCATION="eastus2"
44+
az group create --name $RESOURCE_GROUP --location $LOCATION
45+
```
46+
47+
Results:
48+
49+
<!-- expected_similarity=0.3 -->
50+
```JSON
51+
{
52+
"id": "/subscriptions/xxxxx/resourceGroups/myResourceGroupxxx",
53+
"location": "local",
54+
"managedBy": null,
55+
"name": "myResourceGroupxxx",
56+
"properties": {
57+
"provisioningState": "Succeeded"
58+
},
59+
"tags": null,
60+
"type": "Microsoft.Resources/resourceGroups"
61+
}
4662
```
4763

4864
## Create a virtual machine
4965

50-
Create a virtual machine by using the [az vm create](/cli/azure/vm#az-vm-create) command. The following example creates a VM named myVM. The example uses `Demouser` as the admin username and `Demouser@123` as the admin password. Change these values to something that's appropriate for your environment.
66+
Create a virtual machine by using the [az vm create](/cli/azure/vm#az-vm-create) command. The following example creates a VM named myVM. The example uses `Demouser` as the admin username. Change these values to something that's appropriate for your environment.
5167

5268
```azurecli
69+
export VM_NAME="myVM$RANDOM_SUFFIX"
5370
az vm create \
54-
--resource-group "myResourceGroup" \
55-
--name "myVM" \
56-
--image "UbuntuLTS" \
57-
--admin-username "Demouser" \
58-
--admin-password "Demouser@123" \
59-
--location local
71+
--resource-group $RESOURCE_GROUP \
72+
--name $VM_NAME \
73+
--image "Ubuntu2204" \
74+
--admin-username "azureuser" \
75+
--assign-identity \
76+
--generate-ssh-keys \
77+
--public-ip-sku Standard \
78+
--location $LOCATION
79+
```
80+
81+
Results:
82+
83+
<!-- expected_similarity=0.3 -->
84+
```JSON
85+
{
86+
"fqdns": "",
87+
"id": "/subscriptions/xxxxx/resourceGroups/myResourceGroupxxx/providers/Microsoft.Compute/virtualMachines/myVMxxx",
88+
"location": "local",
89+
"name": "myVMxxx",
90+
"osProfile": {
91+
"computerName": "myVMxxx",
92+
"adminUsername": "Demouser"
93+
},
94+
"publicIpAddress": "x.x.x.x",
95+
"powerState": "VM running",
96+
"provisioningState": "Succeeded"
97+
}
6098
```
6199

62100
The public IP address is returned in the `PublicIpAddress` parameter. Note the address for later use with the virtual machine.
@@ -66,45 +104,83 @@ The public IP address is returned in the `PublicIpAddress` parameter. Note the a
66104
Because this virtual machine runs the IIS web server, you must open port 80 to internet traffic. To open the port, use the [az vm open-port](/cli/azure/vm) command:
67105

68106
```azurecli
69-
az vm open-port --port 80 --resource-group myResourceGroup --name myVM
107+
az vm open-port --port 80 --resource-group $RESOURCE_GROUP --name $VM_NAME
70108
```
71109

72-
## Use SSH to connect to the virtual machine
110+
Results:
111+
112+
```JSON
113+
{
114+
"endPort": 80,
115+
"name": "openPort80",
116+
"port": 80,
117+
"protocol": "Tcp",
118+
"provisioningState": "Succeeded",
119+
"resourceGroup": "myResourceGroupxxx",
120+
"startPort": 80
121+
}
122+
```
73123

74-
From a client computer with SSH installed, connect to the virtual machine. If you work on a Windows client, use [PuTTY](https://www.putty.org/) to create the connection. To connect to the virtual machine, use the following command:
124+
## Use SSH to connect to the virtual machine
75125

76-
```bash
77-
ssh <publicIpAddress>
78-
```
126+
From a client computer with SSH installed, connect to the virtual machine. If you work on a Windows client, use [PuTTY](https://www.putty.org/) to create the connection. To connect to the virtual machine, you can use the `ssh` command.
79127

80128
## Install the NGINX web server
81129

82130
To update package resources and install the latest NGINX package, run the following script:
83131

84132
```bash
85-
#!/bin/bash
86-
87-
# update package source
88-
apt-get -y update
89-
90-
# install NGINX
91-
apt-get -y install nginx
133+
output=$(az vm run-command invoke --resource-group $RESOURCE_GROUP --name $VM_NAME --command-id RunShellScript --scripts 'apt-get -y install nginx')
134+
value=$(echo "$output" | jq -r '.value[0].message')
135+
extracted=$(echo "$value" | awk '/\[stdout\]/,/\[stderr\]/' | sed '/\[stdout\]/d' | sed '/\[stderr\]/d')
136+
echo "$extracted"
92137
```
93138

94139
## View the NGINX welcome page
95140

96-
With the NGINX web server installed, and port 80 open on your virtual machine, you can access the web server by using the virtual machine's public IP address. To do so, open a browser, and go to ```http://<public IP address>```.
97-
98-
![The NGINX web server Welcome page](./media/azure-stack-quick-create-vm-linux-cli/nginx.png)
141+
With the NGINX web server installed, and port 80 open on your virtual machine, you can access the web server by using the virtual machine's public IP address. To do so, open a browser, and go to `http://<public IP address>`. Alternatively, you can use the **curl** command to view the NGINX welcome page:
99142

100-
## Clean up resources
143+
```bash
144+
export PUBLIC_IP=$(az vm show -d -g $RESOURCE_GROUP -n $VM_NAME --query publicIps -o tsv)
101145

102-
Clean up the resources that you don't need any longer. You can use the [az group delete](/cli/azure/group#az-group-delete) command to remove them. Run the following command:
146+
output=$(az vm run-command invoke --resource-group $RESOURCE_GROUP --name $VM_NAME --command-id RunShellScript --scripts 'curl -v http://localhost')
147+
value=$(echo "$output" | jq -r '.value[0].message')
148+
extracted=$(echo "$value" | awk '/\[stdout\]/,/\[stderr\]/' | sed '/\[stdout\]/d' | sed '/\[stderr\]/d')
149+
echo "$extracted"
150+
```
103151

104-
```azurecli
105-
az group delete --name myResourceGroup
152+
Results:
153+
154+
```html
155+
<!DOCTYPE html>
156+
<html>
157+
<head>
158+
<title>Welcome to nginx!</title>
159+
<style>
160+
body {
161+
width: 35em;
162+
margin: 0 auto;
163+
font-family: Tahoma, Verdana, Arial, sans-serif;
164+
}
165+
</style>
166+
</head>
167+
<body>
168+
<h1>Welcome to nginx!</h1>
169+
<p>If you see this page, the nginx web server is successfully installed and
170+
working. Further configuration is required.</p>
171+
172+
<p>For online documentation and support please refer to
173+
<a href="http://nginx.org/">nginx.org</a>.<br/>
174+
Commercial support is available at
175+
<a href="http://nginx.com/">nginx.com</a>.</p>
176+
177+
<p><em>Thank you for using nginx.</em></p>
178+
</body>
179+
</html>
106180
```
107181

182+
![The NGINX web server Welcome page](./media/azure-stack-quick-create-vm-linux-cli/nginx.png)
183+
108184
## Next steps
109185

110-
In this quickstart, you deployed a basic Linux server virtual machine with a web server. To learn more about Azure Stack Hub virtual machines, see [Considerations for virtual machines in Azure Stack Hub](azure-stack-vm-considerations.md).
186+
In this quickstart, you deployed a basic Linux server virtual machine with a web server. To learn more about Azure Stack Hub virtual machines, see [Considerations for virtual machines in Azure Stack Hub](azure-stack-vm-considerations.md).

0 commit comments

Comments
 (0)