Home > Enterprise >  how to login to azure with no web browser
how to login to azure with no web browser

Time:05-13

I am trying to deploy a basic app to an app service in Azure but I want to do it with no web browser, only command line.
I am coming from an AWS background where you can set your api credentials and then do your stuff. I have not been able to find any reference to how to log into azure without a web browser opening up. For instance, you can run python code but it requires you to do 'az login' on the command line, but that opens up a web browser. you can deploy your app with vs code but it opens a web browser to login.

Is there a way to login to azure and use either python or cli without logging into a web browser?

CodePudding user response:

This really depends on your tenants login policy. If you dont have MFA (which I hope you do...) this can work:

az login -u <username> -p <password>

https://docs.microsoft.com/en-us/cli/azure/authenticate-azure-cli#sign-in-with-credentials-on-the-command-line

Otherwise for any application context you might anyway look into using service principals, not users:

az login --service-principal -u <app-id> -p <password-or-cert> --tenant <tenant>

https://docs.microsoft.com/en-us/cli/azure/authenticate-azure-cli#sign-in-with-a-service-principal

CodePudding user response:

You can achieve this by saving the login context to a file with Save-AzContext.

See documentation

The downside of this approach is that the context file can expire based on your policies so you would have to regenerate it from time to time. But once you have the context file saved you can add the authentication to the session with Import-AzContext.

  • Related