Skip to content

Commit c72b701

Browse files
committed
docs: Update PowerShell tab to Linux SSH and align all three tabs
1 parent 6465a5c commit c72b701

1 file changed

Lines changed: 41 additions & 87 deletions

File tree

articles/virtual-network/tutorial-restrict-network-access-to-resources.md

Lines changed: 41 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -633,11 +633,6 @@ The steps required to restrict network access to resources created through Azure
633633
634634
1. Select **Create**.
635635
636-
> [!IMPORTANT]
637-
> Microsoft recommends that you use the most secure authentication flow available. The authentication flow described in this procedure requires a very high degree of trust in the application, and carries risks that are not present in other flows. You should only use this flow when other more secure flows, such as managed identities, aren't viable.
638-
>
639-
> For more information about connecting to a storage account using a managed identity, see [Use a managed identity to access Azure Storage](/entra/identity/managed-identities-azure-resources/tutorial-linux-managed-identities-vm-access?pivots=identity-linux-mi-vm-access-storage).
640-
641636
### [PowerShell](#tab/powershell)
642637
643638
1. Create an Azure storage account with [New-AzStorageAccount](/powershell/module/az.storage/new-azstorageaccount). Replace `<replace-with-your-unique-storage-account-name>` with a name that is unique across all Azure locations, between 3-24 characters in length, using only numbers and lower-case letters.
@@ -928,7 +923,7 @@ To test network access to a storage account, deploy a virtual machine to each su
928923
929924
### Create the first virtual machine
930925
931-
Create a virtual machine in the *subnet-public* subnet with [New-AzVM](/powershell/module/az.compute/new-azvm). When running the command that follows, you're prompted for credentials. The values that you enter are configured as the user name and password for the VM.
926+
Create a virtual machine in the *subnet-public* subnet with [New-AzVM](/powershell/module/az.compute/new-azvm).
932927
933928
```azurepowershell-interactive
934929
$vm1 = @{
@@ -937,7 +932,11 @@ $vm1 = @{
937932
VirtualNetworkName = "vnet-1"
938933
SubnetName = "subnet-public"
939934
Name = "vm-public"
940-
PublicIpAddressName = $null
935+
Image = "Ubuntu2204"
936+
AdminUsername = "azureuser"
937+
PublicIpAddressName = $null
938+
GenerateSshKey = $true
939+
SshKeyName = "vm-public-key"
941940
}
942941
New-AzVm @vm1
943942
```
@@ -953,7 +952,11 @@ $vm2 = @{
953952
VirtualNetworkName = "vnet-1"
954953
SubnetName = "subnet-private"
955954
Name = "vm-private"
955+
Image = "Ubuntu2204"
956+
AdminUsername = "azureuser"
956957
PublicIpAddressName = $null
958+
GenerateSshKey = $true
959+
SshKeyName = "vm-private-key"
957960
}
958961
New-AzVm @vm2
959962
```
@@ -1074,73 +1077,41 @@ The virtual machine you created earlier that is assigned to the **subnet-private
10741077

10751078
### [PowerShell](#tab/powershell)
10761079

1077-
The virtual machine you created earlier that is assigned to the **subnet-private** subnet is used to confirm access to the storage account. The virtual machine you created in the previous section that is assigned to the **subnet-1** subnet is used to confirm that access to the storage account is blocked.
1078-
1079-
### Get storage account access key
1080-
1081-
1. Sign-in to the [Azure portal](https://portal.azure.com/).
1082-
1083-
1. In the search box at the top of the portal, enter **Storage account**. Select **Storage accounts** in the search results.
1084-
1085-
1. In **Storage accounts**, select your storage account.
1086-
1087-
1. In **Security + networking**, select **Access keys**.
1088-
1089-
1. Copy the value of **key1**. You might need to select the **Show** button to display the key.
1090-
1091-
:::image type="content" source="./media/tutorial-restrict-network-access-to-resources/storage-account-access-key.png" alt-text="Screenshot of storage account access key.":::
1092-
10931080
1. In the search box at the top of the portal, enter **Virtual machine**. Select **Virtual machines** in the search results.
10941081

10951082
1. Select **vm-private**.
10961083

1097-
1. Select **Connect** then **Connect via Bastion** in **Overview**.
1084+
1. Select **Bastion** in **Operations**.
10981085

1099-
1. Enter the username and password you specified when creating the virtual machine. Select **Connect**.
1086+
1. Select **SSH Private Key from Local File** for **Authentication Type**.
11001087

1101-
1. Open Windows PowerShell. Use the following script to map the Azure file share to drive Z.
1088+
1. Enter the username you specified when creating the virtual machine.
11021089

1103-
* Replace `<storage-account-key>` with the key you copied in the previous step.
1090+
1. Select the SSH private key file from your local machine.
11041091

1105-
* Replace `<storage-account-name>` with the name of your storage account. In this example, it's **storage8675**.
1092+
1. Select **Connect**.
11061093

1107-
```powershell
1108-
$key = @{
1109-
String = "<storage-account-key>"
1110-
}
1111-
$acctKey = ConvertTo-SecureString @key -AsPlainText -Force
1112-
1113-
$cred = @{
1114-
ArgumentList = "Azure\<storage-account-name>", $acctKey
1115-
}
1116-
$credential = New-Object System.Management.Automation.PSCredential @cred
1094+
1. Use the following commands to mount the Azure file share.
11171095

1118-
$map = @{
1119-
Name = "Z"
1120-
PSProvider = "FileSystem"
1121-
Root = "\\<storage-account-name>.file.core.windows.net\file-share"
1122-
Credential = $credential
1123-
}
1124-
New-PSDrive @map
1125-
```
1096+
* Replace `<storage-account-key>` with the key you retrieved in [Create a storage account](#create-a-storage-account).
11261097

1127-
PowerShell returns output similar to the following example output:
1098+
* Replace `<storage-account-name>` with the name of your storage account. In this example, it's **storage8675**.
11281099

1129-
```output
1130-
Name Used (GB) Free (GB) Provider Root
1131-
---- --------- --------- -------- ----
1132-
Z FileSystem \\storage8675.file.core.windows.net\f...
1100+
```bash
1101+
sudo mkdir /mnt/file-share
1102+
1103+
sudo mount -t cifs //<storage-account-name>.file.core.windows.net/file-share /mnt/file-share -o vers=3.0,username=<storage-account-name>,password=<storage-account-key>,dir_mode=0777,file_mode=0777,serverino
11331104
```
11341105

1135-
The Azure file share successfully mapped to the Z drive.
1106+
1. You receive the `$` prompt with no errors. The Azure file share successfully mounted to **/mnt/file-share**.
11361107

11371108
1. Confirm that the VM has no outbound connectivity to any other public IP addresses:
11381109

1139-
```powershell
1140-
ping bing.com
1110+
```bash
1111+
ping bing.com -c 4
11411112
```
11421113

1143-
You receive no replies, because the network security group associated to the *Private* subnet doesn't allow outbound access to public IP addresses other than the addresses assigned to the Azure Storage service.
1114+
You receive no replies, because the network security group associated to the *subnet-private* subnet doesn't allow outbound access to public IP addresses other than the addresses assigned to the Azure Storage service.
11441115
11451116
1. Close the Bastion connection to **vm-private**.
11461117
@@ -1239,50 +1210,33 @@ The virtual machine you created earlier that is assigned to the **subnet-private
12391210

12401211
### [PowerShell](#tab/powershell)
12411212

1242-
### From vm-1
1213+
### From vm-public
12431214

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

1246-
1. Select **vm-1**.
1217+
1. Select **vm-public**.
12471218

12481219
1. Select **Bastion** in **Operations**.
12491220

1250-
1. Enter the username and password you specified when creating the virtual machine. Select **Connect**.
1221+
1. Select **SSH Private Key from Local File** for **Authentication Type**.
12511222

1252-
1. Repeat the previous command to attempt to map the drive to the file share in the storage account. You might need to copy the storage account access key again for this procedure:
1223+
1. Enter the username you specified when creating the virtual machine.
12531224

1254-
```powershell
1255-
$key = @{
1256-
String = "<storage-account-key>"
1257-
}
1258-
$acctKey = ConvertTo-SecureString @key -AsPlainText -Force
1259-
1260-
$cred = @{
1261-
ArgumentList = "Azure\<storage-account-name>", $acctKey
1262-
}
1263-
$credential = New-Object System.Management.Automation.PSCredential @cred
1225+
1. Select the SSH private key file from your local machine.
12641226

1265-
$map = @{
1266-
Name = "Z"
1267-
PSProvider = "FileSystem"
1268-
Root = "\\<storage-account-name>.file.core.windows.net\file-share"
1269-
Credential = $credential
1270-
}
1271-
New-PSDrive @map
1227+
1. Select **Connect**.
1228+
1229+
1. Attempt to mount the Azure file share. Replace `<storage-account-name>` with the account name and `<storage-account-key>` with the key you retrieved in [Create a storage account](#create-a-storage-account):
1230+
1231+
```bash
1232+
sudo mkdir /mnt/file-share
1233+
1234+
sudo mount -t cifs //<storage-account-name>.file.core.windows.net/file-share /mnt/file-share -o vers=3.0,username=<storage-account-name>,password=<storage-account-key>,dir_mode=0777,file_mode=0777,serverino
12721235
```
12731236

1274-
1. You should receive the following error message:
1237+
1. Access is denied and you receive a `mount error(13): Permission denied` error. The mount fails because **vm-public** is in **subnet-public**, which doesn't have a service endpoint for Azure Storage.
12751238
1276-
```output
1277-
New-PSDrive : Access is denied
1278-
At line:1 char:5
1279-
+ New-PSDrive @map
1280-
+ ~~~~~~~~~~~~~~~~
1281-
+ CategoryInfo : InvalidOperation: (Z:PSDriveInfo) [New-PSDrive], Win32Exception
1282-
+ FullyQualifiedErrorId : CouldNotMapNetworkDrive,Microsoft.PowerShell.Commands.NewPSDriveCommand
1283-
```
1284-
1285-
1. Close the Bastion connection to **vm-1**.
1239+
1. Close the Bastion connection to **vm-public**.
12861240
12871241
1. From your computer, attempt to view the file shares in the storage account with the following command:
12881242

0 commit comments

Comments
 (0)