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
> In this example, you open port 3389 to enable remote access to the Windows Server VM from the internet. However, opening port 3389 to the internet is not recommended to manage production workloads. For information about secure access to Azure VMs, see [What is Azure Bastion?](../../bastion/bastion-overview.md)
77
+
|**Authentication type**| Select **SSH public key**|
78
+
|**Username**| Enter *azureuser*|
79
+
|**SSH public key source**| Select **Generate new key pair**|
80
+
|**Key pair name**| Enter *mySSHKey*|
81
+
|**Public inbound ports**| Select **None**|
48
82
49
83
1. Select the **Networking** tab at the top of the page.
50
-
84
+
51
85
1. On the **Networking** page, enter or select the following values:
52
86
53
-
-**Virtual network**: Accept the default network name.
87
+
-**Virtual network**: Select **myVNet**.
54
88
-**Subnet**: Select **default** if not already selected.
55
-
-**Public IP**: Accept the default public IP configuration.
Use the following steps to create a resource group and a virtual machine.
95
+
Use the following steps to create a resource group, virtual network, and virtual machine.
66
96
67
97
### Create a resource group
68
98
69
99
The following command creates a resource group with [New-AzResourceGroup](/powershell/module/az.resources/new-azresourcegroup).
70
100
71
101
```azurepowershell-interactive
72
102
## Create resource group. ##
73
-
$rg =@{
103
+
$rg =@{
74
104
Name = 'myResourceGroup'
75
105
Location = 'eastus2'
76
106
}
77
107
New-AzResourceGroup @rg
108
+
```
109
+
110
+
### Create a virtual network and subnet
78
111
112
+
The following commands create a virtual network and subnet with [New-AzVirtualNetwork](/powershell/module/az.network/new-azvirtualnetwork) and [Add-AzVirtualNetworkSubnetConfig](/powershell/module/az.network/add-azvirtualnetworksubnetconfig).
The following command creates a Windows Server virtual machine with [New-AzVM](/powershell/module/az.compute/new-azvm). When prompted, provide a username and password to be used as the credentials for the virtual machine:
135
+
Create a credential object for the virtual machine with [Get-Credential](/powershell/module/microsoft.powershell.security/get-credential). Enter a username and password when prompted:
136
+
137
+
```azurepowershell-interactive
138
+
$cred = Get-Credential
139
+
```
140
+
141
+
The following command creates a Linux virtual machine without a public IP address with [New-AzVM](/powershell/module/az.compute/new-azvm). The `-GenerateSshKey` parameter generates an SSH key pair for the VM:
83
142
84
143
```azurepowershell-interactive
85
144
## Create virtual machine. ##
86
145
$vm = @{
87
146
ResourceGroupName = 'myResourceGroup'
88
147
Location = 'East US 2'
89
148
Name = 'myVM'
90
-
PublicIpAddressName = 'myPublicIP'
149
+
Image = 'Ubuntu2204'
150
+
Credential = $cred
151
+
VirtualNetworkName = 'myVNet'
152
+
SubnetName = 'default'
153
+
PublicIpAddressName = ''
154
+
GenerateSshKey = $true
155
+
SshKeyName = 'mySSHKey'
91
156
}
92
157
New-AzVM @vm
93
158
```
94
159
95
160
# [Azure CLI](#tab/azurecli)
96
161
97
-
Use the following steps to create a resource group and a virtual machine.
162
+
Use the following steps to create a resource group, virtual network, and virtual machine.
98
163
99
164
### Create a resource group
100
165
101
166
The following command creates a resource group with [az group create](/cli/azure/group#az-group-create):
102
167
103
-
```azurecli
104
-
az group create --name myResourceGroup --location eastus2
168
+
```azurecli-interactive
169
+
az group create \
170
+
--name myResourceGroup \
171
+
--location eastus2
172
+
```
173
+
174
+
### Create a virtual network and subnet
175
+
176
+
The following command creates a virtual network and subnet with [az network vnet create](/cli/azure/network/vnet#az-network-vnet-create):
177
+
178
+
```azurecli-interactive
179
+
az network vnet create \
180
+
--name myVNet \
181
+
--resource-group myResourceGroup \
182
+
--location eastus2 \
183
+
--address-prefixes 10.0.0.0/16 \
184
+
--subnet-name default \
185
+
--subnet-prefixes 10.0.0.0/24
105
186
```
106
187
107
188
### Create a virtual machine
108
189
109
-
The following command creates a Windows Server virtual machine with [az vm create](/cli/azure/vm#az-vm-create). When prompted, provide a username and password to be used as the credentials for the virtual machine:
190
+
The following command creates a Linux virtual machine without a public IP address with [az vm create](/cli/azure/vm#az-vm-create). The `--generate-ssh-keys` parameter generates an SSH key pair for the VM:
0 commit comments