From 366f2fe95cb9b72e33cf9e426cabba530800cb3b Mon Sep 17 00:00:00 2001 From: vmarcella Date: Tue, 6 Feb 2024 01:05:22 +0000 Subject: [PATCH] [update] line endings/formatting. --- scenarios/ocd/CreateLinuxVMAndSSH/README.md | 243 ++++++++++---------- 1 file changed, 123 insertions(+), 120 deletions(-) diff --git a/scenarios/ocd/CreateLinuxVMAndSSH/README.md b/scenarios/ocd/CreateLinuxVMAndSSH/README.md index 73f4dc2f..f7387399 100644 --- a/scenarios/ocd/CreateLinuxVMAndSSH/README.md +++ b/scenarios/ocd/CreateLinuxVMAndSSH/README.md @@ -1,120 +1,123 @@ -# Create a Linux VM and SSH On Azure - -## Define Environment Variables - -The First step in this tutorial is to define environment variables. - -```bash -export RANDOM_ID="$(openssl rand -hex 3)" -export MY_RESOURCE_GROUP_NAME="myVMResourceGroup$RANDOM_ID" -export REGION=EastUS -export MY_VM_NAME="myVM$RANDOM_ID" -export MY_USERNAME=azureuser -export MY_VM_IMAGE="Canonical:0001-com-ubuntu-minimal-jammy:minimal-22_04-lts-gen2:latest" -``` - -# Login to Azure using the CLI - -In order to run commands against Azure using the CLI you need to login. This is done, very simply, though the `az login` command: - -# Create a resource group - -A resource group is a container for related resources. All resources must be placed in a resource group. We will create one for this tutorial. The following command creates a resource group with the previously defined $MY_RESOURCE_GROUP_NAME and $REGION parameters. - -```bash -az group create --name $MY_RESOURCE_GROUP_NAME --location $REGION -``` - -Results: - - -```json -{ - "id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/myVMResourceGroup", - "location": "eastus", - "managedBy": null, - "name": "myVMResourceGroup", - "properties": { - "provisioningState": "Succeeded" - }, - "tags": null, - "type": "Microsoft.Resources/resourceGroups" -} -``` - -## Create the Virtual Machine - -To create a VM in this resource group we need to run a simple command, here we have provided the `--generate-ssh-keys` flag, this will cause the CLI to look for an avialable ssh key in `~/.ssh`, if one is found it will be used, otherwise one will be generated and stored in `~/.ssh`. We also provide the `--public-ip-sku Standard` flag to ensure that the machine is accessible via a public IP. Finally, we are deploying the latest `Ubuntu 22.04` image. - -All other values are configured using environment variables. - -```bash -az vm create \ - --resource-group $MY_RESOURCE_GROUP_NAME \ - --name $MY_VM_NAME \ - --image $MY_VM_IMAGE \ - --admin-username $MY_USERNAME \ - --assign-identity \ - --generate-ssh-keys \ - --public-ip-sku Standard -``` - -Results: - - -```json -{ - "fqdns": "", - "id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/myVMResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM", - "location": "eastus", - "macAddress": "00-0D-3A-10-4F-70", - "powerState": "VM running", - "privateIpAddress": "10.0.0.4", - "publicIpAddress": "52.147.208.85", - "resourceGroup": "myVMResourceGroup", - "zones": "" -} -``` - -### Enable Azure AD login for a Linux Virtual Machine in Azure - -The following example has deploys a Linux VM and then installs the extension to enable Azure AD login for a Linux VM. VM extensions are small applications that provide post-deployment configuration and automation tasks on Azure virtual machines. - -```bash -az vm extension set \ - --publisher Microsoft.Azure.ActiveDirectory \ - --name AADSSHLoginForLinux \ - --resource-group $MY_RESOURCE_GROUP_NAME \ - --vm-name $MY_VM_NAME -``` - -# Store IP Address of VM in order to SSH -run the following command to get the IP Address of the VM and store it as an environment variable - -```bash -export IP_ADDRESS=$(az vm show --show-details --resource-group $MY_RESOURCE_GROUP_NAME --name $MY_VM_NAME --query publicIps --output tsv) -``` - -# SSH Into VM - - - - - -You can now SSH into the VM by running the output of the following command in your ssh client of choice - -```bash -ssh -o StrictHostKeyChecking=no $MY_USERNAME@$IP_ADDRESS -``` - -# Next Steps - -* [VM Documentation](https://learn.microsoft.com/en-us/azure/virtual-machines/) -* [Use Cloud-Init to initialize a Linux VM on first boot](https://learn.microsoft.com/en-us/azure/virtual-machines/linux/tutorial-automate-vm-deployment) -* [Create custom VM images](https://learn.microsoft.com/en-us/azure/virtual-machines/linux/tutorial-custom-images) -* [Load Balance VMs](https://learn.microsoft.com/en-us/azure/load-balancer/quickstart-load-balancer-standard-public-cli) \ No newline at end of file +# Create a Linux VM and SSH On Azure + +## Define Environment Variables + +The First step in this tutorial is to define environment variables. + +```bash +export RANDOM_ID="$(openssl rand -hex 3)" +export MY_RESOURCE_GROUP_NAME="myVMResourceGroup$RANDOM_ID" +export REGION=EastUS +export MY_VM_NAME="myVM$RANDOM_ID" +export MY_USERNAME=azureuser +export MY_VM_IMAGE="Canonical:0001-com-ubuntu-minimal-jammy:minimal-22_04-lts-gen2:latest" +``` + +# Login to Azure using the CLI + +In order to run commands against Azure using the CLI you need to login. This is done, very simply, though the `az login` command: + +# Create a resource group + +A resource group is a container for related resources. All resources must be placed in a resource group. We will create one for this tutorial. The following command creates a resource group with the previously defined $MY_RESOURCE_GROUP_NAME and $REGION parameters. + +```bash +az group create --name $MY_RESOURCE_GROUP_NAME --location $REGION +``` + +Results: + + + +```json +{ + "id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/myVMResourceGroup", + "location": "eastus", + "managedBy": null, + "name": "myVMResourceGroup", + "properties": { + "provisioningState": "Succeeded" + }, + "tags": null, + "type": "Microsoft.Resources/resourceGroups" +} +``` + +## Create the Virtual Machine + +To create a VM in this resource group we need to run a simple command, here we have provided the `--generate-ssh-keys` flag, this will cause the CLI to look for an avialable ssh key in `~/.ssh`, if one is found it will be used, otherwise one will be generated and stored in `~/.ssh`. We also provide the `--public-ip-sku Standard` flag to ensure that the machine is accessible via a public IP. Finally, we are deploying the latest `Ubuntu 22.04` image. + +All other values are configured using environment variables. + +```bash +az vm create \ + --resource-group $MY_RESOURCE_GROUP_NAME \ + --name $MY_VM_NAME \ + --image $MY_VM_IMAGE \ + --admin-username $MY_USERNAME \ + --assign-identity \ + --generate-ssh-keys \ + --public-ip-sku Standard +``` + +Results: + + + +```json +{ + "fqdns": "", + "id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/myVMResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM", + "location": "eastus", + "macAddress": "00-0D-3A-10-4F-70", + "powerState": "VM running", + "privateIpAddress": "10.0.0.4", + "publicIpAddress": "52.147.208.85", + "resourceGroup": "myVMResourceGroup", + "zones": "" +} +``` + +### Enable Azure AD login for a Linux Virtual Machine in Azure + +The following example has deploys a Linux VM and then installs the extension to enable Azure AD login for a Linux VM. VM extensions are small applications that provide post-deployment configuration and automation tasks on Azure virtual machines. + +```bash +az vm extension set \ + --publisher Microsoft.Azure.ActiveDirectory \ + --name AADSSHLoginForLinux \ + --resource-group $MY_RESOURCE_GROUP_NAME \ + --vm-name $MY_VM_NAME +``` + +# Store IP Address of VM in order to SSH + +run the following command to get the IP Address of the VM and store it as an environment variable + +```bash +export IP_ADDRESS=$(az vm show --show-details --resource-group $MY_RESOURCE_GROUP_NAME --name $MY_VM_NAME --query publicIps --output tsv) +``` + +# SSH Into VM + + + + + +You can now SSH into the VM by running the output of the following command in your ssh client of choice + +```bash +ssh -o StrictHostKeyChecking=no $MY_USERNAME@$IP_ADDRESS +``` + +# Next Steps + +- [VM Documentation](https://learn.microsoft.com/en-us/azure/virtual-machines/) +- [Use Cloud-Init to initialize a Linux VM on first boot](https://learn.microsoft.com/en-us/azure/virtual-machines/linux/tutorial-automate-vm-deployment) +- [Create custom VM images](https://learn.microsoft.com/en-us/azure/virtual-machines/linux/tutorial-custom-images) +- [Load Balance VMs](https://learn.microsoft.com/en-us/azure/load-balancer/quickstart-load-balancer-standard-public-cli)