Quickstart: Create and manage an Azure file share using Azure CLI

This quickstart guides you through the steps to create an Azure file share, mount it to a Windows, Linux, or macOS client, and then upload and download files. Azure Files offers fully managed cloud file shares that are accessible via the industry-standard Server Message Block (SMB) protocol.

Prerequisites

Before you begin, make sure you have the following:

  • An Azure account. If you don't have one, create a free account.
  • Azure CLI installed. You can find instructions for your OS here. Log in to your Azure account using az login.

1. Create a resource group

1

A resource group is a logical container into which Azure resources are deployed and managed. Create a new resource group by running the following command in your Azure CLI.

az group create --name MyResourceGroup --location eastus

Replace MyResourceGroup with a unique name for your resource group and eastus with your desired Azure region.

2. Create a storage account

2

A storage account provides a unique namespace in Azure for your data objects. The following command creates a general-purpose v2 storage account.

az storage account create --name mystorageaccount <YOUR_UNIQUE_STORAGE_ACCOUNT_NAME> --resource-group MyResourceGroup --location eastus --sku Standard_LRS

Replace <YOUR_UNIQUE_STORAGE_ACCOUNT_NAME> with a globally unique name for your storage account.

Tip: Storage account names must be between 3 and 24 characters long and can contain numbers and lowercase letters only.

3. Create an Azure file share

3

Azure file shares are created within a storage account. Run the following command to create a file share.

az storage share create --name myshare --account-name mystorageaccount <YOUR_UNIQUE_STORAGE_ACCOUNT_NAME> --quota 1024

Replace myshare with the desired name for your file share and mystorageaccount <YOUR_UNIQUE_STORAGE_ACCOUNT_NAME> with your storage account name. The --quota parameter sets the share size in GiB (1024 GiB = 1 TiB).

4. Get storage account key

4

You'll need the storage account key to mount the file share.

az storage account keys list --account-name mystorageaccount <YOUR_UNIQUE_STORAGE_ACCOUNT_NAME> --resource-group MyResourceGroup

Note the value of the key field from the output.

Warning: Treat storage account keys as securely as you would your passwords.

5. Mount the file share

5

The process for mounting varies by operating system.

Mount on Windows

Open PowerShell and run the following command, replacing placeholders as needed.

$connectTestResult = systeminfo | findstr /B /C:"System Type"
if ($connectTestResult -match "64-bit") {
    # 64-bit
    [System.Runtime.InteropServices.RuntimeEnvironment]::SystemConfigurationFile
    New-PSDrive -Name Z -PSProvider FileSystem -Root "\\mystorageaccount.file.core.windows.net\myshare" -Persist -Scope Global
} else {
    # 32-bit
    New-PSDrive -Name Z -PSProvider FileSystem -Root "\\mystorageaccount.file.core.windows.net\myshare" -Persist -Scope Global
}
# Save the password for the next reconnect
cmdkey /generic:Azure\ MyStorageAccount /user:Azure\ mystorageaccount <YOUR_UNIQUE_STORAGE_ACCOUNT_NAME> <YOUR_STORAGE_ACCOUNT_KEY>
                            

Mount on Linux

Install the necessary package (cifs-utils) and then mount:

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

sudo mkdir /mnt/myshare
sudo mount -t cifs //mystorageaccount.file.core.windows.net/myshare /mnt/myshare -o username=mystorageaccount,password=<YOUR_STORAGE_ACCOUNT_KEY>,dir_mode=0777,file_mode=0777,serverino
                            

Mount on macOS

Use the Finder's "Connect to Server" option (Command+K) and enter: smb://mystorageaccount.file.core.windows.net/myshare. When prompted for credentials, use your storage account name as the username and your storage account key as the password.

6. Upload and download files

6

Once mounted, you can interact with the file share like any other local drive or directory.

To upload: Copy files from your local machine into the mounted share directory.

To download: Copy files from the mounted share directory to your local machine.

You can also use Azure CLI to upload/download files:

# Upload a file
az storage blob upload --account-name mystorageaccount <YOUR_UNIQUE_STORAGE_ACCOUNT_NAME> --share-name myshare --file <LOCAL_FILE_PATH> --name <DESTINATION_BLOB_NAME>

# Download a file
az storage blob download --account-name mystorageaccount <YOUR_UNIQUE_STORAGE_ACCOUNT_NAME> --share-name myshare --file <LOCAL_DESTINATION_PATH> --name <SOURCE_BLOB_NAME>
                            

Clean up resources

When you're finished with the resource group and all the resources it contains, you can delete them.

az group delete --name MyResourceGroup

This completes the quickstart. You have successfully created an Azure file share, mounted it, and managed files within it.