How to Use Azure Files

Azure Files offers a fully managed cloud file share accessible via the industry-standard Server Message Block (SMB) protocol and Network File System (NFS) protocol. This means you can lift and replace your on-premises file shares in the cloud without needing to manage infrastructure.

Key Concepts

Creating an Azure File Share

You can create an Azure file share using the Azure portal, Azure CLI, PowerShell, or SDKs.

Using Azure Portal

  1. Navigate to your storage account in the Azure portal.
  2. Under "Data storage," select "File shares."
  3. Click "+ File share."
  4. Enter a name for your file share, select a tier (Transaction optimized, Hot, Cool, Premium), and specify the quota.
  5. Click "Create."

Using Azure CLI

First, ensure you have an Azure Storage account. If not, create one:

az storage account create --name mystorageaccount --resource-group myresourcegroup --location eastus --sku Standard_LRS

Then, create a file share:

az storage share create --name myshare --account-name mystorageaccount

Mounting an Azure File Share

Mounting allows you to access your file share as if it were a local drive or directory.

Mounting on Windows

  1. From the file share blade in the Azure portal, click "Connect."
  2. Select the operating system and authentication method (Storage Account Key or Azure AD).
  3. Copy the provided PowerShell or Command Prompt script.
  4. Paste and run the script in your command-line interface.

Example using Storage Account Key (Command Prompt):

net use Z: \\mystorageaccount.file.core.windows.net\myshare /u:Azure\mystorageaccount YOUR_STORAGE_ACCOUNT_KEY

Mounting on Linux

Ensure you have the necessary SMB/NFS packages installed. For SMB:

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

Mount using SMB:

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

For NFS (requires Premium tier and specific configuration):

sudo mount -o vers=4,proto=tcp,sec=sys azure-storage-nfs.file.core.windows.net:/azure-storage-nfs/myshare /mnt/myshare

Security Considerations

Note: For NFS mounts, ensure your client system's UID/GID are properly mapped to prevent permission issues.
Tip: Regularly review access policies and user permissions to maintain a secure environment.
Important: Storage Account Keys grant full access to the storage account. Treat them like passwords and rotate them periodically.

Use Cases

Azure Files provides a flexible, scalable, and secure solution for cloud-based file storage, enabling easy migration and modernizing your application infrastructure.