How to Use Azure File Storage

A step-by-step guide to getting started with Azure File Storage, covering creation, connection, and basic operations.

1. Prerequisites

Before you begin, ensure you have the following:

  • An Azure account. If you don't have one, sign up for a free account.
  • An Azure Storage account. If you need to create one, follow the instructions.
  • Appropriate permissions to access or create storage accounts and file shares.

2. Create a File Share

Azure File Storage is organized into shares. A file share is the root container for your files. You can create a share using the Azure portal, Azure CLI, PowerShell, or client libraries.

Using the Azure Portal:

1

Navigate to your storage account in the Azure portal.

2

In the left-hand menu, under "Data storage," select "File shares."

3

Click the "+ File share" button.

4

Enter a unique name for your file share (e.g., myshare), set the tier (Transaction optimized, Hot, Cool), and optionally a quota. Click "Create."

Using Azure CLI:

Make sure you have Azure CLI installed and are logged in.

az storage share create \
    --name myshare \
    --account-name mystorageaccount \
    --quota 1024 \
    --output table
                    

Replace myshare with your desired share name and mystorageaccount with your storage account name.

3. Mount the File Share

Once a file share is created, you can mount it to your on-premises or cloud-based machines. The method of mounting depends on your operating system.

Mounting on Windows:

You can use the net use command to mount a share. You'll need your storage account name and one of its access keys.

Storing access keys directly in scripts is not recommended for production environments. Consider using Azure Key Vault or managed identities.

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

Replace Z: with your desired drive letter, mystorageaccount with your storage account name, myshare with your share name, and YOUR_STORAGE_ACCOUNT_KEY with your actual storage account key.

Mounting on Linux:

Use the mount command with the CIFS/SMB protocol.

Ensure you have the cifs-utils package installed (e.g., sudo apt-get install cifs-utils on Debian/Ubuntu).

sudo mkdir /mnt/myshare
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
                    

Replace placeholders as described for Windows. The dir_mode and file_mode can be adjusted based on your security requirements.

Mounting on macOS:

Use Finder's "Connect to Server" option or the mount_smbfs command.

From Finder: Go > Connect to Server... and enter smb://mystorageaccount.file.core.windows.net/myshare.


mkdir ~/mnt/myshare
mount_smbfs //mystorageaccount:YOUR_STORAGE_ACCOUNT_KEY@mystorageaccount.file.core.windows.net/myshare ~/mnt/myshare
                    

4. Uploading and Downloading Files

Once the share is mounted, you can interact with it like any other local directory.

Upload a File:

Simply copy the file into the mounted directory.


# Example on Windows
copy C:\path\to\your\local\file.txt Z:\

# Example on Linux/macOS
cp /path/to/your/local/file.txt /mnt/myshare/
                    

Download a File:

Copy the file from the mounted directory to your local system.


# Example on Windows
copy Z:\remote_file.txt C:\path\to\save\
                    
# Example on Linux/macOS
cp /mnt/myshare/remote_file.txt /path/to/save/
                    

5. Next Steps

Congratulations! You've successfully created and mounted an Azure File share. Here are some resources for further exploration: