How to Mount Azure Files Share on Linux

This document provides step-by-step instructions on how to mount an Azure Files share on a Linux operating system. Azure Files offers fully managed cloud file shares that are accessible via the industry-standard Server Message Block (SMB) protocol.

Prerequisites

Before you begin, ensure you have the following:

  • An Azure subscription.
  • An Azure Storage account.
  • An Azure Files share created within the storage account.
  • The storage account name and its access key (or a Shared Access Signature - SAS).
  • A Linux machine with the necessary tools installed.

Install cifs-utils

The cifs-utils package is required to mount SMB/CIFS file systems. You can install it using your distribution's package manager.

On Debian/Ubuntu:

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

On Red Hat/CentOS/Fedora:

sudo yum install cifs-utils

On SUSE:

sudo zypper install cifs-utils

Mounting the Azure Files Share

You can mount the Azure Files share using the mount command. You'll need the storage account name, the share name, and either the storage account key or a SAS token.

Method 1: Using Storage Account Key

This is the most common method. Replace placeholders with your actual values.

  1. Create a mount point directory:
    sudo mkdir /mnt/azure
  2. Mount the share:
    sudo mount -t cifs \\<storage-account-name>.file.core.windows.net/<share-name> /mnt/azure -o vers=3.0,username=<storage-account-name>,password=<storage-account-key>,dir_mode=0777,file_mode=0777,serverino

    Explanation of options:

    • -t cifs: Specifies the file system type as CIFS.
    • \\<storage-account-name>.file.core.windows.net/<share-name>: The UNC path to your Azure Files share.
    • /mnt/azure: The local directory where the share will be mounted.
    • vers=3.0: Specifies the SMB protocol version. Version 3.0 is recommended.
    • username=<storage-account-name>: Your Azure Storage account name.
    • password=<storage-account-key>: Your Azure Storage account key.
    • dir_mode=0777,file_mode=0777: Sets permissions for directories and files. Adjust as needed for security.
    • serverino: Enables server-side inode numbers, which can improve performance.

Security Note:

Storing the storage account key directly in the mount command or a script is not recommended for production environments due to security risks. Consider using a credentials file or Azure Identity for more secure access.

Method 2: Using Shared Access Signature (SAS) Token

Using a SAS token provides more granular control over access permissions and can be more secure than using the full storage account key.

  1. Generate a SAS token for your Azure Files share with appropriate permissions (e.g., Read, Write, List).
  2. Mount the share using the SAS token:
    sudo mount -t cifs \\<storage-account-name>.file.core.windows.net/<share-name> /mnt/azure -o vers=3.0,username=<storage-account-name>,password="sp=<sas-token>&se=<expiry-date>&sv=<sas-version>&sr=<signed-resource>",dir_mode=0777,file_mode=0777,serverino

    Replace <sas-token>, <expiry-date>, <sas-version>, and <signed-resource> with values from your generated SAS token. The password string needs to be formatted correctly.

Automating Mounts with fstab

To ensure the Azure Files share is mounted automatically on system startup, you can add an entry to the /etc/fstab file.

  1. Create a credentials file (recommended for security) to store your account name and key. For example, create /etc/smbcredentials:
    username=<storage-account-name>
    password=<storage-account-key>

    Secure this file:

    sudo chmod 600 /etc/smbcredentials
  2. Add the following line to your /etc/fstab file:
    //<storage-account-name>.file.core.windows.net/<share-name> /mnt/azure cifs vers=3.0,credentials=/etc/smbcredentials,dir_mode=0777,file_mode=0777,serverino,nofail 0 0

    The nofail option prevents the system from halting boot if the mount fails.

  3. Test your fstab entry without rebooting:
    sudo mount -a

Accessing Files

Once mounted, you can access the files on your Azure Files share just like any other local directory:

ls /mnt/azure
cd /mnt/azure
cp myfile.txt /mnt/azure/

Unmounting the Share

To unmount the Azure Files share:

sudo umount /mnt/azure

Tip:

Ensure no processes are using the mount point before attempting to unmount. You can use lsof | grep /mnt/azure to identify processes.

Troubleshooting

  • Permission denied: Check your storage account key, SAS token, and file/directory permissions.
  • Mount error(13): Permission denied: Verify SMB protocol version (try 2.1 if 3.0 fails) and ensure your network allows SMB traffic.
  • Host not found: Double-check the storage account name and the domain suffix (.file.core.windows.net).

For advanced troubleshooting and more detailed information, refer to the official Azure documentation.