Skip to content

Commit cd8890c

Browse files
committed
docs: Update tutorial to use SSH authentication for VMs
1 parent 4f1d833 commit cd8890c

1 file changed

Lines changed: 138 additions & 56 deletions

File tree

articles/virtual-network/tutorial-create-route-table.md

Lines changed: 138 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ titlesuffix: Azure Virtual Network
44
description: In this tutorial, learn how to route network traffic with a route table.
55
author: asudbring
66
ms.service: azure-virtual-network
7-
ms.date: 07/11/2025
7+
ms.date: 02/05/2026
88
ms.author: allensu
99
ms.topic: tutorial
1010
ms.custom:
@@ -64,44 +64,121 @@ A **DMZ** and **Private** subnet are needed for this tutorial. The **DMZ** subne
6464

6565
### [Portal](#tab/portal)
6666

67-
[!INCLUDE [virtual-network-create-with-bastion.md](~/reusable-content/ce-skilling/azure/includes/virtual-network-create-with-bastion.md)]
67+
## Create a resource group
68+
69+
1. Sign in to the [Azure portal](https://portal.azure.com).
70+
71+
1. In the search box at the top of the portal, enter **Resource group**. Select **Resource groups** in the search results.
72+
73+
1. Select **+ Create**.
74+
75+
1. In the **Basics** tab of **Create a resource group**, enter or select the following information:
76+
77+
| Setting | Value |
78+
| ------- | ----- |
79+
| Subscription | Select your subscription. |
80+
| Resource group | Enter **test-rg**. |
81+
| Region | Select **East US 2**. |
82+
83+
1. Select **Review + create**.
84+
85+
1. Select **Create**.
86+
87+
## Create a virtual network
6888

6989
1. In the search box at the top of the portal, enter **Virtual network**. Select **Virtual networks** in the search results.
7090

71-
1. In **Virtual networks**, select **vnet-1**.
91+
1. Select **+ Create**.
7292

73-
1. In **vnet-1**, select **Subnets** from the **Settings** section.
93+
1. On the **Basics** tab of **Create virtual network**, enter or select the following information:
7494

75-
1. In the virtual network's subnet list, select **+ Subnet**.
95+
| Setting | Value |
96+
|---|---|
97+
| **Project details** | |
98+
| Subscription | Select your subscription. |
99+
| Resource group | Select **test-rg**. |
100+
| **Instance details** | |
101+
| Name | Enter **vnet-1**. |
102+
| Region | Select **East US 2**. |
103+
104+
1. Select **Next** to proceed to the **Security** tab.
76105

77-
1. In **Add subnet**, enter or select the following information:
106+
1. Select **Next** to proceed to the **IP Addresses** tab.
107+
108+
1. In the address space box in **Subnets**, select the **default** subnet.
109+
110+
1. In **Edit subnet**, enter or select the following information:
111+
112+
| Setting | Value |
113+
|---|---|
114+
| **Subnet details** | |
115+
| Subnet template | Leave the default **Default**. |
116+
| Name | Enter **subnet-1**. |
117+
| Starting address | Leave the default of **10.0.0.0**. |
118+
| Subnet size | Leave the default of **/24 (256 addresses)**. |
119+
120+
1. Select **Save**.
121+
122+
1. Select **+ Add a subnet**.
123+
124+
1. In **Add a subnet**, enter or select the following information:
78125

79126
| Setting | Value |
80127
| ------- | ----- |
81-
| Subnet purpose | Leave the default of **Default**. |
128+
| **Subnet details** | |
129+
| Subnet template | Leave the default **Default**. |
82130
| Name | Enter **subnet-private**. |
83-
| **IPv4** |
84-
| IPv4 address range | Leave the default of **10.0.0.0/16**. |
85131
| Starting address | Enter **10.0.2.0**. |
86-
| Size | Leave the default of **/24 (256 addresses)**. |
132+
| Subnet size | Leave the default of **/24 (256 addresses)**. |
87133

88134
1. Select **Add**.
89135

90-
1. Select **+ Subnet**.
136+
1. Select **+ Add a subnet**.
91137

92-
1. In **Add subnet**, enter or select the following information:
138+
1. In **Add a subnet**, enter or select the following information:
93139

94140
| Setting | Value |
95141
| ------- | ----- |
96-
| Subnet purpose | Leave the default of **Default**. |
142+
| **Subnet details** | |
143+
| Subnet template | Leave the default **Default**. |
97144
| Name | Enter **subnet-dmz**. |
98-
| **IPv4** |
99-
| IPv4 address range | Leave the default of **10.0.0.0/16**. |
100145
| Starting address | Enter **10.0.3.0**. |
101-
| Size | Leave the default of **/24 (256 addresses)**. |
146+
| Subnet size | Leave the default of **/24 (256 addresses)**. |
102147

103148
1. Select **Add**.
104149

150+
1. Select **Review + create** at the bottom of the screen, and when validation passes, select **Create**.
151+
152+
## Deploy Azure Bastion
153+
154+
Azure Bastion uses your browser to connect to VMs in your virtual network over secure shell (SSH) or remote desktop protocol (RDP) by using their private IP addresses. The VMs don't need public IP addresses, client software, or special configuration. For more information about Azure Bastion, see [Azure Bastion](/azure/bastion/bastion-overview).
155+
156+
>[!NOTE]
157+
>[!INCLUDE [Pricing](~/reusable-content/ce-skilling/azure/includes/bastion-pricing.md)]
158+
159+
1. In the search box at the top of the portal, enter **Bastion**. Select **Bastions** in the search results.
160+
161+
1. Select **+ Create**.
162+
163+
1. In the **Basics** tab of **Create a Bastion**, enter or select the following information:
164+
165+
| Setting | Value |
166+
|---|---|
167+
| **Project details** | |
168+
| Subscription | Select your subscription. |
169+
| Resource group | Select **test-rg**. |
170+
| **Instance details** | |
171+
| Name | Enter **bastion**. |
172+
| Region | Select **East US 2**. |
173+
| Tier | Select **Developer**. |
174+
| **Configure virtual networks** | |
175+
| Virtual network | Select **vnet-1**. |
176+
| Subnet | The **AzureBastionSubnet** is created automatically with an address space of **/26** or larger. |
177+
178+
1. Select **Review + create**.
179+
180+
1. Select **Create**.
181+
105182
### [PowerShell](#tab/powershell)
106183

107184
Create a resource group with [New-AzResourceGroup](/powershell/module/az.resources/new-azresourcegroup). The following example creates a resource group named *test-rg* for all resources created in this article.
@@ -191,6 +268,7 @@ $bastionParams = @{
191268
PublicIpAddressName = "public-ip-bastion"
192269
PublicIpAddressRgName = "test-rg"
193270
VirtualNetworkRgName = "test-rg"
271+
Sku = "Basic"
194272
}
195273
New-AzBastion @bastionParams -AsJob
196274
```
@@ -263,7 +341,8 @@ az network bastion create \
263341
--name bastion \
264342
--vnet-name vnet-1 \
265343
--public-ip-address public-ip-bastion \
266-
--location eastus2
344+
--location eastus2 \
345+
--sku Basic \
267346
--no-wait
268347
```
269348

@@ -295,10 +374,10 @@ Network virtual appliances (NVAs) are virtual machines that help with network fu
295374
| VM architecture | Leave the default of **x64**. |
296375
| Size | Select a size. |
297376
| **Administrator account** | |
298-
| Authentication type | Select **Password**. |
377+
| Authentication type | Select **SSH public key**. |
299378
| Username | Enter a username. |
300-
| Password | Enter a password. |
301-
| Confirm password | Reenter password. |
379+
| SSH public key source | Select **Generate new key pair**. |
380+
| Key pair name | Enter **vm-nva-key**. |
302381
| **Inbound port rules** | |
303382
| Public inbound ports | Select **None**. |
304383

@@ -324,8 +403,13 @@ Network virtual appliances (NVAs) are virtual machines that help with network fu
324403
Create the virtual machine with [New-AzVM](/powershell/module/az.compute/new-azvm). The following example creates a virtual machine named *vm-nva*.
325404

326405
```azurepowershell-interactive
327-
# Create a credential object
328-
$cred = Get-Credential
406+
# Create an SSH key for the virtual machine
407+
$sshParams = @{
408+
ResourceGroupName = "test-rg"
409+
Name = "vm-nva-ssh-key"
410+
PublicKey = (ssh-keygen -t rsa -b 4096 -f ~/.ssh/vm-nva-key -N "" -q; Get-Content ~/.ssh/vm-nva-key.pub -Raw)
411+
}
412+
New-AzSshKey @sshParams
329413
330414
# Define the virtual machine parameters
331415
$vmParams = @{
@@ -334,10 +418,10 @@ $vmParams = @{
334418
Name = "vm-nva"
335419
ImageName = "Canonical:ubuntu-24_04-lts:server-gen1:latest"
336420
Size = "Standard_DS1_v2"
337-
Credential = $cred
338421
VirtualNetworkName = "vnet-1"
339422
SubnetName = "subnet-dmz"
340423
PublicIpAddressName = $null # No public IP address
424+
SshKeyName = "vm-nva-ssh-key"
341425
}
342426
343427
# Create the virtual machine
@@ -394,10 +478,10 @@ The public virtual machine is used to simulate a machine in the public internet.
394478
| VM architecture | Leave the default of **x64**. |
395479
| Size | Select a size. |
396480
| **Administrator account** | |
397-
| Authentication type | Select **Password**. |
481+
| Authentication type | Select **SSH public key**. |
398482
| Username | Enter a username. |
399-
| Password | Enter a password. |
400-
| Confirm password | Reenter password. |
483+
| SSH public key source | Select **Generate new key pair**. |
484+
| Key pair name | Enter **vm-public-key**. |
401485
| **Inbound port rules** | |
402486
| Public inbound ports | Select **None**. |
403487

@@ -439,10 +523,10 @@ The public virtual machine is used to simulate a machine in the public internet.
439523
| VM architecture | Leave the default of **x64**. |
440524
| Size | Select a size. |
441525
| **Administrator account** | |
442-
| Authentication type | Select **Password**. |
526+
| Authentication type | Select **SSH public key**. |
443527
| Username | Enter a username. |
444-
| Password | Enter a password. |
445-
| Confirm password | Reenter password. |
528+
| SSH public key source | Select **Generate new key pair**. |
529+
| Key pair name | Enter **vm-private-key**. |
446530
| **Inbound port rules** | |
447531
| Public inbound ports | Select **None**. |
448532

@@ -467,8 +551,13 @@ The public virtual machine is used to simulate a machine in the public internet.
467551
Create a virtual machine in the *subnet-1* subnet with [New-AzVM](/powershell/module/az.compute/new-azvm). The following example creates a virtual machine named *vm-public* in the *subnet-public* subnet of the *vnet-1* virtual network.
468552

469553
```azurepowershell-interactive
470-
# Create a credential object
471-
$cred = Get-Credential
554+
# Create an SSH key for the virtual machine
555+
$sshParams = @{
556+
ResourceGroupName = "test-rg"
557+
Name = "vm-public-ssh-key"
558+
PublicKey = (ssh-keygen -t rsa -b 4096 -f ~/.ssh/vm-public-key -N "" -q; Get-Content ~/.ssh/vm-public-key.pub -Raw)
559+
}
560+
New-AzSshKey @sshParams
472561
473562
# Define the virtual machine parameters
474563
$vmParams = @{
@@ -477,10 +566,10 @@ $vmParams = @{
477566
Name = "vm-public"
478567
ImageName = "Canonical:ubuntu-24_04-lts:server-gen1:latest"
479568
Size = "Standard_DS1_v2"
480-
Credential = $cred
481569
VirtualNetworkName = "vnet-1"
482570
SubnetName = "subnet-1"
483571
PublicIpAddressName = $null # No public IP address
572+
SshKeyName = "vm-public-ssh-key"
484573
}
485574
486575
# Create the virtual machine
@@ -490,8 +579,13 @@ New-AzVM @vmParams
490579
Create a virtual machine in the *subnet-private* subnet.
491580

492581
```azurepowershell-interactive
493-
# Create a credential object
494-
$cred = Get-Credential
582+
# Create an SSH key for the virtual machine
583+
$sshParams = @{
584+
ResourceGroupName = "test-rg"
585+
Name = "vm-private-ssh-key"
586+
PublicKey = (ssh-keygen -t rsa -b 4096 -f ~/.ssh/vm-private-key -N "" -q; Get-Content ~/.ssh/vm-private-key.pub -Raw)
587+
}
588+
New-AzSshKey @sshParams
495589
496590
# Define the virtual machine parameters
497591
$vmParams = @{
@@ -500,10 +594,10 @@ $vmParams = @{
500594
Name = "vm-private"
501595
ImageName = "Canonical:ubuntu-24_04-lts:server-gen1:latest"
502596
Size = "Standard_DS1_v2"
503-
Credential = $cred
504597
VirtualNetworkName = "vnet-1"
505598
SubnetName = "subnet-private"
506599
PublicIpAddressName = $null # No public IP address
600+
SshKeyName = "vm-private-ssh-key"
507601
}
508602
509603
# Create the virtual machine
@@ -603,40 +697,28 @@ az network nic update \
603697

604698
## Enable IP forwarding in the operating system
605699

606-
In this section, turn on IP forwarding for the operating system of the **vm-nva** virtual machine to forward network traffic. Use the Azure Bastion service to connect to the **vm-nva** virtual machine.
700+
In this section, turn on IP forwarding for the operating system of the **vm-nva** virtual machine to forward network traffic. Use the Run Command feature to execute a script on the virtual machine.
607701

608702
1. In the search box at the top of the portal, enter **Virtual machine**. Select **Virtual machines** in the search results.
609703

610704
1. In **Virtual machines**, select **vm-nva**.
611705

612-
1. Select **Connect**, then **Connect via Bastion** in the **Overview** section.
706+
1. Expand **Operations** then select **Run command**.
613707

614-
1. Enter the username and password you entered when the virtual machine was created.
708+
1. Select **RunShellScript**.
615709

616-
1. Select **Connect**.
617-
618-
1. Enter the following information at the prompt of the virtual machine to enable IP forwarding:
710+
1. Enter the following script in the **Run Command Script** window:
619711

620712
```bash
621-
sudo vim /etc/sysctl.conf
622-
```
623-
624-
1. In the Vim editor, remove the **`#`** from the line **`net.ipv4.ip_forward=1`**:
625-
626-
Press the **Insert** key.
627-
628-
```bash
629-
# Uncomment the next line to enable packet forwarding for IPv4
630-
net.ipv4.ip_forward=1
713+
sudo sed -i 's/#net.ipv4.ip_forward=1/net.ipv4.ip_forward=1/' /etc/sysctl.conf
714+
sudo sysctl -p
631715
```
632716

633-
Press the **Esc** key.
634-
635-
Enter **`:wq`** and press **Enter**.
717+
1. Select **Run**.
636718

637-
1. Close the Bastion session.
719+
1. Wait for the script to complete. The output shows the IP forwarding setting has been enabled.
638720

639-
1. Restart the virtual machine.
721+
1. Return to the **Overview** page of **vm-nva** and select **Restart** to restart the virtual machine.
640722

641723
## Create a route table
642724

0 commit comments

Comments
 (0)