# Getting started with Azure CLI

This chapter is to login to the Azure CLI from your student machine as you may not want to use the Azure Cloud shell all the time.

## Login to the Azure CLI on the student machine

First check if you are already logged in

```bash
az account list
```

If you aren't logged in, you should get this output.

```bash
Please run "az login" to access your accounts.
[]
```

Now that we know we don't have Azure account setup, we can use the following command to begin. The `--use-device-code` parameter is used to generate a code that can be used to authenticate with the web backend

```bash
az login --use-device-code
```

We will get something like this

```bash
To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code XXXXXXX to authenticate.
```

> Note the code XXXXXXX mentioned.

Browse to the URL and enter the code when asked.

![Enter the code](https://441555962-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4co4Py2DyRvsKhKa-u%2F-M4dKiFJor0gJgjeW_pX%2F-M4dKq_glwx7NpPwOXhw%2Fazure-cli-login-1.png?generation=1586610279645597\&alt=media)

Confirm by clicking on Continue

![Click on continue](https://441555962-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4co4Py2DyRvsKhKa-u%2F-M4dKiFJor0gJgjeW_pX%2F-M4dKq_iNeTSIVC_ht4W%2Fazure-cli-login-2.png?generation=1586610279295534\&alt=media)

Select your account

![Select your account](https://441555962-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4co4Py2DyRvsKhKa-u%2F-M4dKiFJor0gJgjeW_pX%2F-M4dKq_kVu3M7YM41Ghr%2Fazure-cli-login-3.png?generation=1586610279922146\&alt=media)

Web page will confirmed you are logged in

![Web page will confirmed you are logged in](https://441555962-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4co4Py2DyRvsKhKa-u%2F-M4dKiFJor0gJgjeW_pX%2F-M4dKq_m8LE95d3FxgcK%2Fazure-cli-login-4.png?generation=1586610279131320\&alt=media)

Switch back to the window where you typed the `az login` command

![Succesfully logged in and authenticated](https://441555962-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M4co4Py2DyRvsKhKa-u%2F-M4dKiFJor0gJgjeW_pX%2F-M4dKq_oFwPqS5cj-rW3%2Fazure-cli-login-5.png?generation=1586610279513741\&alt=media)

Note the `id` from the previous output.

## Once you are logged in

### List the azure account

```bash
az account list
```

**Only if you were already logged in**, get the default Azure account if you have more than one.

```bash
az account list | jq '.[] | select(.isDefault==true) | {subname: .name, username: .user.name}'
```

Set this new account as default

```bash
az account set --subscription <PROVIDE YOUR ID FROM PREVIOUS OUTPUT>
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://kingsabri-2.gitbook.io/pwining-aws-and-asure/getting-started-with-azure/setup/getting-started-with-azure-cli.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
