How To Generate SAS Token For Azure Storage

Generating a Shared Access Signature (SAS) token for your Azure Storage is important for managing secure access to different storage resources. In this article, I will walk you through all the approaches to doing this.

How To Generate SAS Token For Azure Storage

A SAS token for Azure storage can help you secure access to a resource inside your Azure storage account. Let’s discuss each method individually.

Approach-1: Using Azure Portal

To Generate SAS Token For Azure Storage, Follow the below steps.

1. Log in to the Azure Portal.

2. Search for Storage accounts and then click on the search result Storage accounts as shown in the screenshot below.

sas token for azure storage

3. Click on the specific storage from the lists for the one you wish to generate the SAS access token.

how to get sas token for azure storage

4. Expand the Security + networking tab, then click on the Shared access signature link as shown in the screenshot below.

how to generate sas token for azure storage account

5. Select the required options for Allowed permissions, set the start and expiration date, etc., based on your requirements, and finally, click on the Generate SAS and connection string button, as highlighted in the screenshot below.

generate sas token for azure storage
azure blob storage sas token

Now, the SAS token is generated successfully below the button, as shown in the screenshot below.

Create SAS Token For Azure Storage

Check out: Create a storage account in Azure

Approach-2: Using PowerShell

We can execute the below PowerShell script to generate the SAS access token for the alazureml7822510715 storage account.

$strgact_name = "alazureml7822510715"

$strgact_key = "ogCGYSTLBnJkYtO5O9lPdB5K4uRjEKF9a8x+21JouWOYeiDi/mBq4eq7M7CAsyCv0r6RvqoB5sq3+ASttMeBSg=="

$mycontext = New-AzStorageContext -StorageAccountName $strgact_name -StorageAccountKey $strgact_key

#you can also add other parameters like ExpiryTime etc based on your requirement.
New-AzStorageAccountSASToken -Service Blob -ResourceType Service,Container,Object -Permission rl -Context $mycontext

The query executed successfully and the SAS token also got generated successfully as shown in the screenshot below.

create sas token azure storage

Check out: Move storage account to another region

Approach-3: Using Azure CLI

We can also execute the Azure CLI script below to generate the SAS Token.

az storage container generate-sas --account-name alazureml7822510715 --name azureml --permissions acdlrw --expiry 2024-11-15 --auth-mode login --as-user

After executing the above query, I got the SAS token successfully as highlighted in the screenshot below.

how to get sas token for azure storage

Video Tutorial

Conclusion

Generating a Shared Access Signature (SAS) token is a great way of securing your Azure resource inside your Azure storage account. As explained in this article, you can get a SAS token for your Azure storage account using Azure Portal, PowerShell, or Azure CLI.

You may also like following the articles below.

Azure Virtual Machine

DOWNLOAD FREE AZURE VIRTUAL MACHINE PDF

Download our free 25+ page Azure Virtual Machine guide and master cloud deployment today!