In this blog, I am going to show the process of installation of Azure CLI tool and then using this tool to create a ubuntu virtual machine and then accessing this virtual machine through ssh and then add one user and then adding their private key and running one job in their environment.
The first thing you need is the tools that are required. The first tool you required is Azure CLI . You can install Azure CLI simple using the following command:
sudo apt install azure-cli
To use the Azure CLI tool you need first to login into your account through terminal. For this purpose use following command:
az login
When you enter this you will be redirected to the browser, there you can enter your login detail. When you entered then you will get this type of message on your terminal.
You have logged in. Now let us find all the subscriptions to which you have access...
The following tenants require Multi-Factor Authentication (MFA). Use 'az login --tenant TENANT_ID' to explicitly login to a tenant.
b76df79f-0110-465c-90f3-07df4642315d
[
{
"cloudName": "AzureCloud",
"homeTenantId": "4ea778976d-32bd-7f5f-aaa5-084cb61a0b0f",
"id": "37623de4-e2df-4d06-8754-bd88314b4bd0",
"isDefault": true,
"managedByTenants": [],
"name": "Azure for Students",
"state": "Enabled",
"tenantId": "5ea9899d-30bd-4f6f-aaa5-084cb61a0b0f",
"user": {
"name": "halcyoona@gmail.com",
"type": "user"
}
}
]
Now you are logged in and you can use the Azure CLI tool to create resources from CLI.
az group create --name halcyoona-group --location eastus
When you execute above command you get following output:
{
"id": "/subscriptions/95623de4-e1df-4c06-9954-bd66314b4bd0/resourceGroups/halcyoona-group",
"location": "eastus",
"managedBy": null,
"name": "halcyoona-group",
"properties": {
"provisioningState": "Succeeded"
},
"tags": null,
"type": "Microsoft.Resources/resourceGroups"
}
In Azure, all resources are allocated in a resource management group. Resource groups provide logical groupings of resources that make them easier to work with as a collection.
You have to set the name of the resource and then location. Now the resource group is set then move to next creating a virtual machine with this resource.
From now We look forward to creating a virtual machine using the Azure CLI. Use following command to create virtual machine.
az vm create --resource-group halcyoona-group --name halcyoonaVM --image UbuntuLTS --generate-ssh-keys --output json --verbose
In this you have to set the name of the virtual machine. Second Image you want in your machine. Generate ssh key to access it without password using your private key and if you do not specify key name, it will create a key in ~/.ssh/id_rsa.pub by default. Output will be in json form.
Read More »