Efficiently delete large mount directories

mkdir empty_dir
rsync -a --delete empty_dir/    yourdirectory/

https://unix.stackexchange.com/questions/37329/efficiently-delete-large-directory-containing-thousands-of-files

Encrypting a Windows VM with data disk in Azure

  1. Create a new VM and vault as per https://docs.microsoft.com/en-us/azure/virtual-machines/windows/disk-encryption-cli-quickstart
  2. Add a data disk to the VM
  3. RDP to the VM, initialize and format the data disk. Until you initialize and format the disk, it the data disk(s) will not get encrypted
  4. Encrypt the VM

Check if the disks are encrypted:

PowerShell
Get-AzVmDiskEncryptionStatus -ResourceGroupName -VMname <VMNAME
OsVolumeEncrypted : Encrypted
DataVolumesEncrypted : Encrypted
OsVolumeEncryptionSettings : Microsoft.Azure.Management.Compute.Models.DiskEncryptionSettings
ProgressMessage : Provisioning succeeded

AZ CLI
az vm show –name MyVM -g MyResourceGroup

Azure Portal
Locate the VM
Go to Disks
Both data and OS disks have SSE with PMK & ADE or SSE with CMK & ADE encryption status

From Windows Disk Management
Check if the drives are Bitlocker Encrypted in Disk Management.

PS:
Encrypt using PMK (Platform Managed Key)
az vm encryption enable -g MyResourceGroup –name MyVM –disk-encryption-keyvault myKV

Encrypt using CMK (Customer Managed Key)

Create a new KEK
az keyvault key create –name myKEK –vault-name myKV -kty RSA-HSM

Encrypt VM
az vm encryption enable -g “MyResourceGroup” –name MyVM –disk-encryption-keyvault myKV –key-encryption-key myKEK

Use keys with existing EC2 instance

I have an existing key pair. I want to ssh to a new instance using the key.

If below steps are followed it will save lot of time and there will be no need to stop the running instance.

Start new t1.micro EC2 instance, using new key pair. Make sure you create it in the same subnet, otherwise you will have to terminate the instance and create it again.
SSH to the new micro instance and copy content of ~/.ssh/authorized_keys somewhere on your computer.
Login to main instance with old ssh key.
Copy & replace the file content from point 2 to ~/.ssh/authorized_keys
Now you can login again only with new key. Old key will not work anymore.
That is it. Enjoy 🙂

Thanks!