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
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
2. Create a storage account
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
3. Create an Azure file share
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
4. Get storage account key
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
5. Mount the file share
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 (
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:
6. Upload and download files
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.