Swiftorial Logo
Home
Swift Lessons
Matchups
CodeSnaps
Tutorials
Career
Resources

Using Azure with Linux

Introduction

Microsoft Azure is a popular cloud computing platform that supports a wide range of operating systems, including Linux. This tutorial will guide you through the steps to set up and manage Azure services using a Linux-based environment.

Prerequisites

Before we begin, ensure you have the following:

  • Azure account
  • Basic knowledge of Linux command line
  • A Linux machine (local or VM)

Installing Azure CLI on Linux

The Azure Command-Line Interface (CLI) is a set of commands used to create and manage Azure resources. To install Azure CLI on your Linux machine, follow these steps:

Update the repository information:

sudo apt-get update

Install Azure CLI:

curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash

Verify the installation:

az --version
azure-cli 2.27.2
core 2.27.2
telemetry 1.0.6
Python (Linux) 3.8.10 (default, Sep 28 2021, 16:10:42)
[GCC 9.3.0]

Logging into Azure

After installing the Azure CLI, you need to log in to your Azure account:

az login

This command will open a browser window prompting you to sign in with your Azure credentials. After successful login, the CLI will display your account information.

[ { "cloudName": "AzureCloud", "homeTenantId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "isDefault": true, "managedByTenants": [], "name": "My Azure Subscription", "state": "Enabled", "tenantId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "user": { "name": "user@example.com", "type": "user" } } ]

Creating a Virtual Machine

To create a new virtual machine (VM) in Azure using the CLI, follow these steps:

Create a resource group:

az group create --name myResourceGroup --location eastus

Create the VM:

az vm create --resource-group myResourceGroup --name myVM --image UbuntuLTS --admin-username azureuser --generate-ssh-keys

This command will create a VM with Ubuntu LTS image and generate SSH keys for secure login.

{ "fqdns": "", "id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM", "location": "eastus", "macAddress": "00-0D-3A-35-39-20", "powerState": "VM running", "privateIpAddress": "10.0.0.4", "publicIpAddress": "40.121.34.65", "resourceGroup": "myResourceGroup", "zones": "" }

Connecting to the Virtual Machine

To connect to your newly created VM, use SSH:

ssh azureuser@40.121.34.65

Replace 40.121.34.65 with the public IP address of your VM.

Managing Azure Resources

You can use the Azure CLI to manage various Azure resources. Here are some common commands:

List all resource groups:

az group list

Delete a resource group:

az group delete --name myResourceGroup --yes --no-wait

Conclusion

In this tutorial, we covered the basics of using Azure with a Linux environment. We went through installing the Azure CLI, logging in, creating a virtual machine, and managing Azure resources. With these skills, you can now start leveraging the power of Azure in your Linux workflows.