How to encrypt an Azure Virtual Machine
In this post, I will show you how you can easily encrypt an Azure Virtual, Machine.
Disks are encrypted by using cryptographic keys that are secured in an Azure Key Vault. You control these cryptographic keys and can audit their use.
Virtual disks on Windows VMs are encrypted at rest by using BitLocker. There’s no charge for encrypting virtual disks in Azure.
First thing we will have to do is to create a new Key Vault using the Azure Portal.
Click on + Create Resource
![](http://www.thatlazyadmin.com/wp-content/uploads/2019/08/word-image-7.png)
In the Marketplace search bar type: Key Vault
![](http://www.thatlazyadmin.com/wp-content/uploads/2019/08/word-image-8.png)
Click on Create to deploy key vault
![](http://www.thatlazyadmin.com/wp-content/uploads/2019/08/word-image-9.png)
Select your subscription, Resource Group and provide a name for the new Key Vault. Then click on Review + Create
![](http://www.thatlazyadmin.com/wp-content/uploads/2019/08/word-image-10.png)
Once you have reviewed your config and your validation passed, click Create.
Once the Vault creation is complete, open the newly created Key vault.
To encrypt the Azure Vm, we need to use key vault keys, to generate a new key. Navigate to Keys in Key Vault.
Ps. The key vault must be in the same region as the virtual machine.
![](http://www.thatlazyadmin.com/wp-content/uploads/2019/08/word-image-11.png)
Click on +Generate/Import to generate a new key for the Azure VM.
Provide a name for the key and encryption type as well as if the key should have an expiration date.
Once done click on + Create
![](http://www.thatlazyadmin.com/wp-content/uploads/2019/08/word-image-12.png)
To enable encryption on the Operating disk of the virtual machine, navigate to the virtual machine which you want to encrypt. Then click on Disks.
![](http://www.thatlazyadmin.com/wp-content/uploads/2019/08/word-image-13.png)
On the Disks page, you will notice that your disks is currently not encrypted.
![](http://www.thatlazyadmin.com/wp-content/uploads/2019/08/word-image-14.png)
To enable encryption, click on encryption on the top section of the page.
![](http://www.thatlazyadmin.com/wp-content/uploads/2019/08/word-image-15.png)
On the encryption page, select your disk.
![](http://www.thatlazyadmin.com/wp-content/uploads/2019/08/word-image-16.png)
Next click on “Select a key vault and key for encryption”
Select your key vault and newly created key.
![](http://www.thatlazyadmin.com/wp-content/uploads/2019/08/word-image-17.png)
Click on Save, to start the encryption process.
![](http://www.thatlazyadmin.com/wp-content/uploads/2019/08/word-image-18.png)
You will receive a warning that your virtual machine will be rebooted during the process. Please remember to save any work if this is a production vm.
Click yes to start the process.
![](http://www.thatlazyadmin.com/wp-content/uploads/2019/08/word-image-19.png)
Once the disk encryption is complete, you will notice on the Virtual Machine disk that the status has changed to encrypted.
![](http://www.thatlazyadmin.com/wp-content/uploads/2019/08/word-image-20.png)
You can also enable disk encryption using PowerShell.
To get started, connect to Azure
Connect-AzAccount
![](http://www.thatlazyadmin.com/wp-content/uploads/2019/08/word-image-21.png)
Once you have a connection established, run the following script to enable encryption on your Azure Virtual Machine.
Ps. Note that you will have to change the following to fit your environment.
- ResourcegroupName
- VaultName
- VMName
- VaultKey
$keyVault = Get-AzKeyVault -VaultName "lazylabkeys" -ResourceGroupName "RSG-MSFT-SA-N-01";
$diskEncryptionKeyVaultUrl = $keyVault.VaultUri;
$keyVaultResourceId = $keyVault.ResourceId;
$keyEncryptionKeyUrl = (Get-AzKeyVaultKey -VaultName "lazylabkeys" -Name "lazylab-cl01700").Key.kid;
Set-AzVMDiskEncryptionExtension -ResourceGroupName "RSG-MSFT-SA-N-CLIENT-MACHINES" `
-VMName "lazylab-cl01" `
-DiskEncryptionKeyVaultUrl $diskEncryptionKeyVaultUrl `
-DiskEncryptionKeyVaultId $keyVaultResourceId `
-KeyEncryptionKeyUrl $keyEncryptionKeyUrl `
-KeyEncryptionKeyVaultId $keyVaultResourceId
You will receive a waring message that the virtual machine needs to be rebooted for the encryption process to start, type Y to start the process.
It will also take about 10 – 15 min for the encryption process to complete.
![](http://www.thatlazyadmin.com/wp-content/uploads/2019/08/word-image-22.png)
Once completed, you will see the success code is True. Meaning that the encryption was successful.
![](http://www.thatlazyadmin.com/wp-content/uploads/2019/08/word-image-23.png)
You can also run the following to verify if disk encryption has been enabled.
Get-AzVmDiskEncryptionStatus -ResourceGroupName "RSG-MSFT-SA-N-CLIENT-MACHINES" -VMName "lazylab-cl01"
![](http://www.thatlazyadmin.com/wp-content/uploads/2019/08/word-image-24.png)
And that’s how you can quickly enable disk encryption for your Azure virtual machines.
![](http://www.thatlazyadmin.com/wp-content/uploads/2018/06/word-image-14.png)
Be First to Comment