Home Microsoft AzureAzure Files SMB Shares: Mount Them Securely on Linux VMs

Azure Files SMB Shares: Mount Them Securely on Linux VMs

by Knowledge Base Linux
Clean technical illustration of an Azure Files SMB share mounted on a Linux virtual machine, with no text in the image

If you run Linux virtual machines in Azure and need shared file storage that behaves like a local disk, learning how to use azure files smb shares is one of the most practical skills you can pick up. Azure Files exposes fully managed file shares over the SMB protocol, so your VMs can read and write the same files without you having to build, patch, or back up a file server of your own. Mounted correctly, a share feels like any other directory on the system, while Azure handles redundancy, snapshots, and scaling behind the scenes.

Clean technical illustration of a secure Azure Files SMB mount configuration with a credentials file and encrypted connection, with no text in the image

This guide walks you through the whole process: creating a storage account and file share with the Azure CLI, mounting it on a Linux VM with cifs-utils, locking the mount down with a protected credentials file and SMB 3.0 encryption, and fixing the most common errors. It assumes you already have an Azure subscription and a Linux VM running in Azure. The commands target Ubuntu and Debian, with notes for RHEL-based distributions where the package names differ.

Prerequisites

Before you start, make sure you have the following in place:

  • An Azure subscription with permission to create storage accounts.
  • A Linux VM in Azure, running Ubuntu 22.04 or 24.04, Debian 12, or a comparable distribution.
  • The Azure CLI installed on your workstation or on the VM itself. Check with az --version.
  • SSH access to the VM with sudo privileges.
  • A resource group to hold the storage account. You can create one with az group create if you do not have one yet.

One networking point matters more than any other for an Azure Files SMB setup: SMB traffic uses TCP port 445. Azure VMs can reach Azure Files over port 445 without any special configuration, but many ISPs and corporate networks block outbound port 445. If you plan to mount the share from a machine outside Azure, test port 445 first. We cover workarounds in the troubleshooting section.

Create the Storage Account and File Share

Every Azure Files SMB share lives inside a storage account. Storage account names must be globally unique, use only lowercase letters and numbers, and be between 3 and 24 characters long. Pick a name that reflects the purpose of the share, such as teamfilesprod01, and check availability before scripting the rest of the setup.

Create the storage account with the Azure CLI. The Standard_LRS SKU keeps a single local copy of your data and is the cheapest option for general use; switch to a zone-redundant SKU if you need resilience against a datacenter outage.

az storage account create \
  --name teamfilesprod01 \
  --resource-group rg-files \
  --location eastus \
  --sku Standard_LRS \
  --kind StorageV2

Next, create the Azure Files SMB share itself. The quota is set in GiB and can range from a few gigabytes up to 100 TiB for a standard share. A quota is a ceiling, not a reservation, so you only pay for the capacity you actually use.

az storage share-rm create \
  --resource-group rg-files \
  --storage-account teamfilesprod01 \
  --name shared \
  --quota 100

The share-rm variant of the command uses the Azure Resource Manager control plane, which is the recommended approach for new shares. Finally, retrieve one of the storage account keys. You will need it for the Azure Files SMB mount credentials, so treat it like a password and never commit it to version control.

az storage account keys list \
  --resource-group rg-files \
  --account-name teamfilesprod01 \
  --query "[0].value" --output tsv

Mount Azure Files SMB Shares on Linux

Mounting an azure files smb share on Linux uses the kernel CIFS client, provided by the cifs-utils package. Install it on the VM first to enable Azure Files SMB mounting:

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

On AlmaLinux, Rocky Linux, or RHEL, use sudo dnf install -y cifs-utils instead. Next, create a mount point and a credentials file. The credentials file holds the storage account name as the username and the account key as the password. Keeping credentials out of /etc/fstab itself is important: fstab is world-readable by default, while a dedicated credentials file can be locked down to root only.

sudo mkdir -p /mnt/azfiles
sudo mkdir -p /etc/smbcredentials
sudo tee /etc/smbcredentials/teamfilesprod01.cred > /dev/null <<EOF
username=teamfilesprod01
password=YOUR_STORAGE_ACCOUNT_KEY
EOF
sudo chmod 600 /etc/smbcredentials/teamfilesprod01.cred

Verify the permissions with ls -l /etc/smbcredentials/. The file must show -rw------- and be owned by root. If any other user can read it, anyone with access to the VM can copy your storage account key.

Now add the Azure Files SMB mount to /etc/fstab so it survives reboots. The share path uses the storage account name, the file.core.windows.net endpoint, and the share name. The mount options deserve attention:

  • nofail lets the VM boot even if the share is temporarily unreachable, so a storage outage never blocks startup.
  • vers=3.0 forces SMB 3.0, which encrypts traffic in transit. Azure Files requires SMB 3.0 with encryption for connections from outside Azure, and it is the right choice inside Azure too.
  • sec=ntlmssp selects the authentication mechanism used with storage account keys.
  • serverino and nosharesock improve compatibility and performance for Azure Files mounts.
  • dir_mode and file_mode set the permissions that files and directories in the share appear to have on the Linux side.
//teamfilesprod01.file.core.windows.net/shared /mnt/azfiles cifs nofail,credentials=/etc/smbcredentials/teamfilesprod01.cred,dir_mode=0777,file_mode=0777,serverino,nosharesock,actimeo=30,vers=3.0,sec=ntlmssp 0 0

Apply the new entry without rebooting, then confirm the mount is active:

sudo mount -a
df -h /mnt/azfiles

If df shows the share with its size and available space, the mount succeeded. Adjust dir_mode and file_mode to match your application: 0777 is convenient for shared team directories, but a stricter mode such as 0755 and 0644 is safer when only one service writes to the share.

Verify Read and Write Access

Never assume an Azure Files SMB mount works just because it appears in df output. Write a test file, read it back, and check it from a second location, such as the Azure portal’s file share browser or another VM mounting the same share. Shared access is the whole point of Azure Files, so verifying it now saves confusion later.

echo "mount test $(date)" | sudo tee /mnt/azfiles/mount-test.txt
cat /mnt/azfiles/mount-test.txt
ls -l /mnt/azfiles/

Delete the test file once you have confirmed both directions work. Also confirm that the share survives a reboot: restart the VM, log back in, and check that /mnt/azfiles is mounted again. If the mount is missing after a reboot, check /etc/fstab for typos and review the boot log with journalctl -b | grep -i cifs.

For production use, consider enabling Azure Files SMB share snapshots in the Azure portal. Snapshots capture the share at a point in time and give you a simple rollback path if files are deleted or corrupted. They are billed on the changed data only, so the cost of a sensible snapshot schedule is usually small compared with the value of a quick restore.

Secure Your Azure Files SMB Mount

A working mount is only half the job. A secure azure files smb setup needs attention in three places: credentials, encryption, and network access. First, rotate your storage account keys periodically. Azure provides two keys precisely so you can rotate without downtime: update the credentials file to the second key, remount, then regenerate the first key.

Second, understand the encryption layers already protecting your data. Azure Storage encrypts all data at rest automatically with Storage Service Encryption, using Microsoft-managed keys by default. You can bring your own keys through Azure Key Vault if your compliance requirements demand it. In transit, the vers=3.0 option in your fstab entry ensures SMB encryption, and the storage account’s “secure transfer required” setting blocks unencrypted connections outright. Verify that setting is enabled in the portal under the storage account’s Configuration page.

Third, restrict network access. By default a storage account accepts connections from the public internet. If your VMs are the only clients, limit the storage account firewall to your virtual network or to selected IP ranges. This single change blocks the most common attack path, which is a leaked key being used from an unrelated network. For a deeper comparison of storage options, see our guide to Azure Blob Storage containers and access tiers, and for hardening the VM itself, read how to create and harden an Azure Linux virtual machine.

Identity-Based Authentication: An Advanced Option

Storage account keys are simple, but they are shared secrets: anyone holding the key has full access. For environments with many users, identity-based authentication is the better long-term model. With Microsoft Entra Domain Services, you can enable Active Directory authentication on the storage account, join your Linux VMs to the managed domain, and grant access through role assignments and NTFS-style permissions on individual directories.

This approach removes shared keys from the picture and gives you per-user auditing, but it adds real complexity: a managed domain, domain-joined VMs, and Kerberos configuration. It is worth the effort for team file shares with sensitive data, but it is overkill for a single VM mounting an application share. Start with key-based Azure Files SMB authentication, get the workload running, and migrate to identity-based access when your team or compliance needs justify it.

Troubleshooting Azure Files SMB Mounts

Most Azure Files SMB mount failures fall into a small set of causes. Work through them in order before changing anything else.

Port 445 is blocked

If mount hangs or times out, and the VM is outside Azure, port 445 is the likely culprit. Test it with nc -zv teamfilesprod01.file.core.windows.net 445. If the connection fails, your ISP or corporate firewall is blocking the port. The reliable fixes are a point-to-site VPN into your Azure virtual network, an ExpressRoute circuit, or moving the workload into an Azure VM. There is no supported way to change the port that Azure Files listens on.

Mount error 13: Permission denied

Error 13 almost always means wrong credentials or an SMB version problem. Check that the username in the credentials file is exactly the storage account name, that the key has no trailing whitespace or line breaks, and that vers=3.0 is present in the mount options. Also confirm that “secure transfer required” is enabled and that the storage account firewall is not blocking your VM’s IP address.

Mount succeeds but writes fail

If you can read the Azure Files SMB share but cannot write to it, check the file_mode and dir_mode options and the ownership of the mount point. Remember that with key-based authentication, all access appears to come from the storage account itself, so Linux-side ownership is cosmetic: the real permission boundary is the storage account key and firewall. If files created on one VM do not appear on another, check that both VMs mount the same share and that neither has a stale cached view; remounting clears client-side caching issues.

Conclusion

Azure Files gives Linux VMs shared, durable file storage without the burden of running a file server. Create the storage account and share with the Azure CLI, mount with cifs-utils and a root-only credentials file, enforce SMB 3.0 encryption, and verify the mount survives a reboot before you depend on it. For the full feature set, including snapshots, soft delete, and identity-based access, consult the official Azure Files documentation on Microsoft Learn. With those pieces in place, your azure files smb share is ready for production workloads, from shared application data to team directories mounted on every VM in your fleet.

You may also like

KbLinux

Typically replies within a day

Hello, Welcome to the site. Please click below button for chatting me through Telegram.