Mount an Azure file share
Before you begin this article, make sure you've read configure directory and file-level permissions over SMB.
The process described in this article verifies that your SMB file share and access permissions are set up correctly and that you can mount your SMB Azure file share. Remember that share-level role assignment can take some time to take effect.
Sign in to the client using the credentials of the identity that you granted permissions to.
Applies to
File share type | SMB | NFS |
---|---|---|
Standard file shares (GPv2), LRS/ZRS | ||
Standard file shares (GPv2), GRS/GZRS | ||
Premium file shares (FileStorage), LRS/ZRS |
Mounting prerequisites
Before you can mount the Azure file share, make sure you've gone through the following prerequisites:
- If you're mounting the file share from a client that has previously connected to the file share using your storage account key, make sure that you've disconnected the share, removed the persistent credentials of the storage account key, and are currently using AD DS credentials for authentication. For instructions on how to remove cached credentials with storage account key and delete existing SMB connections before initializing a new connection with AD DS or Microsoft Entra credentials, follow the two-step process on the FAQ page.
- Your client must have unimpeded network connectivity to your AD DS. If your machine or VM is outside of the network managed by your AD DS, you'll need to enable VPN to reach AD DS for authentication.
Mount the file share from a domain-joined VM
Run the PowerShell script below or use the Azure portal to persistently mount the Azure file share and map it to drive Z: on Windows. If Z: is already in use, replace it with an available drive letter. The script will check to see if this storage account is accessible via TCP port 445, which is the port SMB uses. Remember to replace the placeholder values with your own values. For more information, see Use an Azure file share with Windows.
Unless you're using custom domain names, you should mount Azure file shares using the suffix file.core.chinacloudapi.cn
, even if you set up a private endpoint for your share.
$connectTestResult = Test-NetConnection -ComputerName <storage-account-name>.file.core.chinacloudapi.cn -Port 445
if ($connectTestResult.TcpTestSucceeded) {
cmd.exe /C "cmdkey /add:`"<storage-account-name>.file.core.chinacloudapi.cn`" /user:`"localhost\<storage-account-name>`""
New-PSDrive -Name Z -PSProvider FileSystem -Root "\\<storage-account-name>.file.core.chinacloudapi.cn\<file-share-name>" -Persist -Scope global
} else {
Write-Error -Message "Unable to reach the Azure storage account via port 445. Check to make sure your organization or ISP is not blocking port 445, or use Azure P2S VPN, Azure S2S VPN, or Express Route to tunnel SMB traffic over a different port."
}
You can also use the net-use
command from a Windows prompt to mount the file share. Remember to replace <YourStorageAccountName>
and <FileShareName>
with your own values.
net use Z: \\<YourStorageAccountName>.file.core.chinacloudapi.cn\<FileShareName>
If you run into issues, see Unable to mount Azure file shares with AD credentials.
Mount the file share from a non-domain-joined VM or a VM joined to a different AD domain
Non-domain-joined VMs or VMs that are joined to a different AD domain than the storage account can access Azure file shares if they have unimpeded network connectivity to the domain controllers and provide explicit credentials (username and password). The user accessing the file share must have an identity and credentials in the AD domain that the storage account is joined to.
To mount a file share from a non-domain-joined VM, use the notation username@domainFQDN, where domainFQDN is the fully qualified domain name. This will allow the client to contact the domain controller to request and receive Kerberos tickets. You can get the value of domainFQDN by running (Get-ADDomain).Dnsroot
in Active Directory PowerShell.
For example:
net use Z: \\<YourStorageAccountName>.file.core.chinacloudapi.cn\<FileShareName> /user:<username@domainFQDN>
Note
Azure Files doesn't support SID to UPN translation for users and groups from a non-domain joined VM or a VM joined to a different domain via Windows File Explorer. If you want to view file/directory owners or view/modify NTFS permissions via Windows File Explorer, you can do so only from domain joined VMs.
Mount file shares using custom domain names
If you don't want to mount Azure file shares using the suffix file.core.chinacloudapi.cn
, you can modify the suffix of the storage account name associated with the Azure file share, and then add a canonical name (CNAME) record to route the new suffix to the endpoint of the storage account. The following instructions are for single-forest environments only. To learn how to configure environments that have two or more forests, see Use Azure Files with multiple Active Directory forests.
Note
Azure Files only supports configuring CNAMES using the storage account name as a domain prefix. If you don't want to use the storage account name as a prefix, consider using DFS namepaces.
In this example, we have the Active Directory domain onpremad1.com, and we have a storage account called mystorageaccount which contains SMB Azure file shares. First, we need to modify the SPN suffix of the storage account to map mystorageaccount.onpremad1.com to mystorageaccount.file.core.chinacloudapi.cn.
This will allow clients to mount the share with net use \\mystorageaccount.onpremad1.com
because clients in onpremad1 will know to search onpremad1.com to find the proper resource for that storage account.
To use this method, complete the following steps:
Make sure you've set up identity-based authentication and synced your AD user account(s) to Microsoft Entra ID.
Modify the SPN of the storage account using the
setspn
tool. You can find<DomainDnsRoot>
by running the following Active Directory PowerShell command:(Get-AdDomain).DnsRoot
setspn -s cifs/<storage-account-name>.<DomainDnsRoot> <storage-account-name>
Add a CNAME entry using Active Directory DNS Manager and follow the steps below for each storage account in the domain that the storage account is joined to. If you're using a private endpoint, add the CNAME entry to map to the private endpoint name.
- Open Active Directory DNS Manager.
- Go to your domain (for example, onpremad1.com).
- Go to "Forward Lookup Zones".
- Select the node named after your domain (for example, onpremad1.com) and right-click New Alias (CNAME).
- For the alias name, enter your storage account name.
- For the fully qualified domain name (FQDN), enter
<storage-account-name>
.<domain-name>
, such as mystorageaccount.onpremad1.com. The hostname part of the FQDN must match the storage account name. Otherwise you'll get an access denied error during the SMB session setup. - For the target host FQDN, enter
<storage-account-name>
.file.core.chinacloudapi.cn - Select OK.
You should now be able to mount the file share using storageaccount.domainname.com. You can also mount the file share using the storage account key.
Next step
If the identity you created in AD DS to represent the storage account is in a domain or OU that enforces password rotation, you might need to update the password of your storage account identity in AD DS.