Use the Cross-platform CLI for Azure DevOps using personal access tokens

Azure DevOps Services | Azure DevOps Server 2022 - Azure DevOps Server 2019

Use personal access tokens (PATs) with the cross-platform CLI for Azure DevOps.

Important

We don't recommend using basic authentication. For Azure DevOps Services, see Sign in with a PAT.

Prerequisites

Personal access token

Create a personal access token and paste it into the sign-in command.

~$ tfx login
Copyright Microsoft Corporation

> Service URL: {url}
> Personal access token: xxxxxxxxxxxx
Logged in successfully

See the following examples of valid URLs:

  • https://marketplace.visualstudio.com
  • https://youraccount.visualstudio.com/DefaultCollection

Configure for Basic authentication

Warning

We don't recommend basic authentication. Turning on IIS basic authentication causes various issues, and you should use personal access tokens (PATs) instead. For example, if you turn on IIS basic authentication, GIT command line stops working.

Follow these steps to enable basic auth for your Azure DevOps instance:

Warning

Basic authentication sends usernames and passwords in plaintext. Consider configuring Azure DevOps Server to use SSL to enable secure communication when using basic auth.

  1. Install the Basic Authentication feature for IIS in Server Manager.

    Screenshot of configure basic authentication feature.

  2. Open IIS Manager and expand to the Azure DevOps Server website, double-click the Authentication tile in the Features view.

  3. Choose Basic Authentication in the list of authentication methods. Choose Enable in the right hand column. You should now see Basic Authentication enabled.

Note

Leave the domain and realm settings for Basic Authentication empty.

tfx sign in with Basic authentication

Now you can start to use tfx against your server. Sign in before you issue commands.

  1. Enter the following command:

    tfx login --auth-type basic
    
  2. Add your service url.

  3. Add your username. Use domain\user (for example, fabrikam\peter). If you're working on a workgroup machine, use machinename\user.

  4. Add your password. Enter the password for the username that you previously entered.

You can now use any other tfx command.

> tfx login --auth-type basic
Copyright Microsoft Corporation

Enter service url > http://localhost:8080/tfs/defaultcollection
Enter username > fabfiber\peter
Enter password > *******
logged in successfully