Azure Key Vault Linux VM secrets are the right place to keep the credentials your servers need, because the alternative, a password in a config file or an environment variable on disk, is a secret that is copied into backups, shared in support tickets, and forgotten when an engineer leaves. Key Vault centralises secrets in one encrypted, audited store, and a Linux VM with a managed identity can retrieve exactly the secrets it needs, with no password stored on the VM at all. This guide creates a vault, stores a secret, gives a VM a managed identity with the minimum role to read that secret, and retrieves it from inside the VM, then covers the access errors that most often block first setups.
Two concepts decide whether this works. A managed identity is an identity Azure manages for the VM itself: the platform handles the credential, rotates it, and presents it to Azure services, so the VM never holds a client secret. Role-based access control decides what that identity may do: the Key Vault Secrets User role grants read access to secrets and nothing else, which is the least-privilege choice for an application VM. Older vaults used access policies instead of roles, and a vault created with the old model will ignore role assignments until its permission model is changed, which is a common source of confusion. If your VM networking is already locked down, our guide to Azure Private Endpoints for Blob Storage shows the parallel pattern for keeping Azure service traffic off the public internet.

Prerequisites
You need an Azure subscription, the Azure CLI installed and logged in, a resource group, and a Linux VM in that subscription, or permission to create one. You should be comfortable running az commands and SSHing into the VM. The examples use a vault in the same region as the VM, a secret called db-password, and a VM called app-vm. Vault names must be globally unique across Azure, so if your chosen name is taken, add a suffix and use that name consistently through the rest of the guide.
Azure Key Vault Linux VM: Create the Vault and Store a Secret
Create the vault with Azure RBAC as the permission model, then store a secret in it. The RBAC model is the current default and the one this guide assumes; if you create a vault in the portal, check that its permission model is set to Azure role-based access control, because the older Vault access policy model behaves differently. Enable soft delete, which is on by default for new vaults, so an accidentally deleted secret can be recovered within the retention period instead of being lost immediately.
az keyvault create --name kv-app-prod-001 --resource-group rg-app --location eastus
az keyvault secret set --vault-name kv-app-prod-001 --name db-password --value "correct-horse-battery-staple"
Never put a real production password in a shell command in a shared terminal, because it lands in shell history; the example value above is a placeholder. In practice, read the value from a file or a prompt, or set the secret through a pipeline variable that is masked in logs. The official Microsoft documentation on Key Vault secrets with the Azure CLI shows the same commands plus the portal equivalent, and it documents the secret versioning behaviour that matters for rotation.
Azure Key Vault Linux VM: Give the VM a Managed Identity
Assign a system-assigned managed identity to the VM, then grant that identity the Key Vault Secrets User role scoped to the vault. Scoping the role to the vault, rather than to the whole resource group or subscription, is the least-privilege choice: a compromised VM can read secrets from that one vault, not from every vault in the subscription. The principal ID in the role assignment is the identity object ID that the assign command returns, so capture it and use it in the next command.
az vm identity assign --name app-vm --resource-group rg-app
PRINCIPAL_ID=$(az vm show --name app-vm --resource-group rg-app --query identity.principalId -o tsv)
VAULT_ID=$(az keyvault show --name kv-app-prod-001 --resource-group rg-app --query id -o tsv)
az role assignment create --role "Key Vault Secrets User" --assignee $PRINCIPAL_ID --scope $VAULT_ID
Role assignments can take a few minutes to propagate, so if the first retrieval attempt fails, wait and retry before changing anything. Now retrieve the secret from inside the VM. The Azure CLI on the VM can authenticate with the managed identity directly, which is the simplest path for scripts and testing. Log in with the identity, then show the secret value.
ssh azureuser@app-vm
az login --identity
az keyvault secret show --vault-name kv-app-prod-001 --name db-password --query value -o tsv
Applications that cannot run the Azure CLI can use the instance metadata service instead: request a token for the Key Vault resource, then call the vault REST API with that token. The API version in the URL matters, so use a current version such as 7.4, and treat the token as a short-lived credential that should never be logged. For connecting to VMs without a public IP at all, see our guide to Azure Bastion for Linux VMs, which removes the SSH exposure that this setup otherwise still carries.
Troubleshooting
When secret retrieval fails with a forbidden error, check the permission model first. A vault using the old access-policy model ignores role assignments, so either switch the vault to RBAC or add an access policy for the managed identity instead. When the error is about the identity not being found, the managed identity may not be assigned yet, or the role assignment has not propagated; verify with vm show that identity is present, and wait a few minutes before retrying. When the Azure CLI on the VM reports that it cannot find an identity, confirm you are running az login –identity on the VM itself, not on your workstation, because the identity exists only on the VM.
When the secret value comes back empty or the secret is not found, check the vault name and the secret name for typos, and check whether the secret was stored in a different vault or resource group. Vault names are globally unique, so a similarly named vault in another subscription is a real possibility. When a script works interactively but fails in a scheduled job, check whether the job runs as a different user without access to the CLI login session; a service that needs secrets unattended should use the metadata-service token flow or a user-assigned managed identity attached to the VM, rather than an interactive login.
Conclusion
Azure Key Vault Linux VM setups follow a short, safe pattern: create the vault with RBAC, store secrets once, give the VM a system-assigned managed identity, scope the Secrets User role to that vault, and retrieve secrets on demand instead of storing them on disk. The remaining work is operational: rotate secrets on a schedule, audit Key Vault logs for unexpected reads, and remove the old config-file secrets the vault replaces. Do that cleanup, or the vault is just a second copy of the problem it was meant to solve.