Mounting an Azure File Share
Mounting an Azure File Share allows you to access your files directly from your on-premises servers or cloud virtual machines as if it were a local drive. This guide covers the common methods for mounting a file share on Windows and Linux.
Prerequisites
- An Azure Storage account with a File Share created.
- The storage account name and its access key.
- Appropriate network connectivity to your Azure region.
Mounting on Windows
You can mount an Azure File Share on Windows using Server Message Block (SMB) protocol. This can be done via the command line or PowerShell.
Using Command Prompt (cmd.exe)
Open Command Prompt as an administrator and use the net use command:
net use Z: \\yourstorageaccountname.file.core.windows.net\yourfilesharename /u:Azure\yourstorageaccountname yourstorageaccountkey
- Replace
Z:with your desired drive letter. - Replace
yourstorageaccountnamewith your storage account name. - Replace
yourfilesharenamewith the name of your file share. - Replace
yourstorageaccountkeywith your storage account access key.
Using PowerShell
Open PowerShell as an administrator and use the New-PSDrive cmdlet:
New-PSDrive -Name Z -PSProvider FileSystem -Root "\\yourstorageaccountname.file.core.windows.net\yourfilesharename" -Persist -Credential (Get-Credential)
You will be prompted to enter your storage account name and access key as credentials.
Mounting on Linux
Mounting on Linux also uses the SMB protocol. You'll need to install the cifs-utils package first.
Install cifs-utils
For Debian/Ubuntu:
sudo apt update
sudo apt install cifs-utils
For RHEL/CentOS/Fedora:
sudo yum install cifs-utils
Create a Mount Point and Mount
Create a directory where you want to mount the share:
sudo mkdir /mnt/azurefiles
Mount the file share:
sudo mount -t cifs //yourstorageaccountname.file.core.windows.net/yourfilesharename /mnt/azurefiles -o vers=3.0,username=yourstorageaccountname,password=yourstorageaccountkey,dir_mode=0777,file_mode=0777,serverino
- Replace placeholders as with the Windows example.
vers=3.0specifies the SMB version.dir_modeandfile_modeset permissions for mounted directories and files.- For security, consider storing credentials in a separate file rather than on the command line or in scripts.
Auto-mounting with fstab
To mount the file share automatically on boot, edit your /etc/fstab file:
//yourstorageaccountname.file.core.windows.net/yourfilesharename /mnt/azurefiles cifs vers=3.0,username=yourstorageaccountname,password=yourstorageaccountkey,dir_mode=0777,file_mode=0777,_netdev 0 0
Security Note: Storing credentials directly in fstab is not recommended. Consider using a credentials file with restricted permissions.
Troubleshooting
Common issues include incorrect credentials, network connectivity problems, or incorrect SMB version specified.