Azure Files Quickstart

This guide helps you get started with Azure Files by creating a file share and mounting it.

1. Create an Azure Storage Account

First, you need an Azure Storage account. If you don't have one, you can create it through the Azure portal, Azure CLI, or Azure PowerShell.

Using Azure CLI

Open your Azure CLI and run the following commands:


# Set your subscription ID
az account set --subscription ""

# Set variables for resource group and storage account names
resourceGroup="myResourceGroup"
storageAccount="mystorageaccount$(openssl rand -hex 4)" # Unique name

# Create a resource group
az group create --name $resourceGroup --location eastus

# Create a storage account
az storage account create \
    --name $storageAccount \
    --resource-group $resourceGroup \
    --location eastus \
    --sku Standard_LRS \
    --kind StorageV2
        

2. Create an Azure File Share

Once your storage account is created, you can create a file share within it. You'll need the storage account name and its primary access key.

Get Storage Account Key


storageAccountKey=$(az storage account keys list \
    --account-name $storageAccount \
    --resource-group $resourceGroup \
    --query "[0].value" \
    --output tsv)

echo $storageAccountKey
        

Create the File Share

Now, create the file share. Replace myshare with your desired share name.


az storage share create \
    --name "myshare" \
    --account-name $storageAccount \
    --account-key $storageAccountKey
        

3. Mount the File Share

You can mount your Azure File share to different operating systems using various methods. Here are examples for Windows, Linux, and macOS.

Mount on Windows

Open PowerShell as an administrator and run:


$connectTestResult = Test-NetConnection -ComputerName $($storageAccount + ".file.core.windows.net") -Port 445
if ($connectTestResult.TcpTestSucceeded) {
    cmd.exe /C "cmdkey /generic:\"$($storageAccount).file.core.windows.net\" /user:\"$($storageAccount)\" `"$storageAccountKey`""
    New-PSDrive -Name Z -PSProvider FileSystem -Root "\\$($storageAccount).file.core.windows.net\myshare" -Persist
    Write-Host "Successfully mounted Azure File Share."
} else {
    Write-Error -Message "Unable to reach the Azure storage account via port 445. Check to ensure that outbound port 445 is not blocked."
}
        

You can then access the mounted drive (e.g., Z:) in File Explorer.

Mount on Linux

Install the cifs-utils package if you don't have it:


sudo apt-get update
sudo apt-get install cifs-utils
        

Create a mount point and mount the share:


sudo mkdir /mnt/myshare
sudo mount -t cifs //$storageAccount.file.core.windows.net/myshare /mnt/myshare -o vers=3.0,username=$storageAccount,password=$storageAccountKey,dir_mode=0777,file_mode=0777,serverino
        

Mount on macOS

You can use the Finder's "Connect to Server" option. Enter the following in the server address field:


smb://<storage-account-name>.file.core.windows.net/myshare
        

When prompted for credentials, use:

For more persistent mounts on Linux and macOS, consider configuring /etc/fstab or using automount solutions.

4. Next Steps

Congratulations! You have successfully created an Azure file share and mounted it. You can now:

Remember to secure your storage account access keys. Consider using Azure Key Vault for managing secrets.