| title | Azure CLI Script Sample - Rotate storage account access keys |
|---|---|
| description | Create an Azure Storage account, then retrieve and rotate its account access keys. |
| services | storage |
| author | stevenmatthew |
| ms.service | azure-storage |
| ms.devlang | azurecli |
| ms.topic | sample |
| ms.date | 03/02/2022 |
| ms.author | shaas |
| ms.custom | devx-track-azurecli |
This script creates an Azure Storage account, displays the new storage account's access keys, then renews (rotates) the keys.
[!INCLUDE quickstarts-free-trial-note]
[!INCLUDE azure-cli-prepare-your-environment.md]
[!INCLUDE cli-launch-cloud-shell-sign-in.md]
:::code language="azurecli" source="~/azure_cli_scripts/storage/rotate-storage-account-keys/rotate-storage-account-keys.sh" id="FullScript":::
[!INCLUDE cli-clean-up-resources.md]
az group delete --name $resourceGroup
This script uses the following commands to create the storage account and retrieve and rotate its access keys. Each item in the table links to command-specific documentation.
| Command | Notes |
|---|---|
| az group create | Creates a resource group in which all resources are stored. |
| az storage account create | Creates an Azure Storage account in the specified resource group. |
| az storage account keys list | Displays the storage account access keys for the specified account. |
| az storage account keys renew | Regenerates the primary or secondary storage account access key. |
For more information on the Azure CLI, see Azure CLI documentation.
Additional storage CLI script samples can be found in the Azure CLI samples for Azure Blob storage.