The az logout command is part of the azure-cli tool, which is the official Command-Line Interface (CLI) provided by Microsoft for managing Azure resources and services.
The az logout command is used to log out from an Azure subscription in the Azure CLI. Here’s an overview of its functionality:
- Ending the Current Session: When you run the az logout command, it terminates the current session that you have established with an Azure subscription. This action revokes the authentication token associated with the session, ensuring that you no longer have access to the resources and services within that subscription.
- Switching Subscriptions: Azure CLI allows you to work with multiple Azure subscriptions simultaneously. When you log in with the az login command, you establish a session with a specific Azure subscription. If you want to switch to a different subscription, you can use the az account set command. However, if you no longer need to work with a particular subscription, you can log out from it using the az logout command.
- Clearing Authentication Tokens: When you log out from an Azure subscription, the az logout command clears the authentication token associated with that subscription from the local machine. This ensures that subsequent commands or sessions initiated within the Azure CLI will require re-authentication to access the resources and services of the logged-out subscription.
- Enhancing Security: Logging out from Azure subscriptions using the az logout command can help improve security. By explicitly terminating the session and clearing authentication tokens, you reduce the risk of unauthorized access to your Azure resources, especially if you are working in a shared environment or on a public computer.
It’s important to note that logging out with the az logout command only affects the current session in the Azure CLI. It does not affect any other sessions or authentication tokens associated with Azure services accessed through other means, such as Azure portal or SDKs.
The az logout command is a convenient way to end your session with an Azure subscription in the Azure CLI. By using this command, you can ensure that you no longer have access to the resources and services within the logged-out subscription, providing an extra layer of security and control over your Azure environment.
az logout Command Examples
1. Log out from the active account:
# az logout
2. Log out a specific username:
# az logout --username firstname.lastname@example.org