Authentication
TeamCity CLI supports several authentication methods. This page covers interactive login, guest access, token-based authentication for CI/CD, multi-server setup, and automatic authentication within TeamCity builds.
Interactive login
The standard way to authenticate is with the teamcity auth login command:
This starts an interactive flow:
Enter your TeamCity server URL (for example,
https://teamcity.example.com).If the server supports PKCE authentication, the CLI opens your browser to approve access directly — no token copying needed.
Otherwise, the CLI opens the TeamCity Access Tokens page for you to create and paste a token manually.
The CLI validates the token and stores it securely.
To authenticate with a specific server URL:
To skip browser-based authentication and enter a token manually:
To pass the token directly (for example, from a password manager):
Browser-based login (PKCE)
When PKCE is enabled on the TeamCity server, teamcity auth login authenticates via the browser automatically:
The CLI starts a temporary local server on your machine.
Your browser opens a TeamCity authorization page.
After you approve, the browser redirects back to the CLI with an authorization code.
The CLI exchanges the code for an access token.
This flow follows the OAuth 2.0 PKCE standard (RFC 7636) and does not require you to copy or paste any tokens.
PKCE tokens have an expiry date. The CLI tracks this and shows a warning when the token is about to expire or has expired:
Check authentication status
View the current authentication state:
This displays the server URL, server version, authenticated username, and token storage method.
Log out
Remove stored credentials for the current server:
Guest access
If the TeamCity server has guest access enabled, you can authenticate without a token:
With a specific server URL:
Guest authentication provides read-only access. It uses the /guestAuth/ API prefix and does not require or store any credentials.

Guest access via environment variable
For CI/CD environments where guest access is sufficient:
PowerShell:
CMD:
Token storage
TeamCity CLI stores access tokens using the system keyring when available:
Platform | Keyring |
|---|---|
macOS | Keychain |
Linux | GNOME Keyring (or compatible secret service) |
Windows | Credential Manager |
If the system keyring is unavailable, the CLI falls back to storing the token in plain text in the configuration file at ~/.config/tc/config.yml. To force plain text storage (for example, in headless environments), use the --insecure-storage flag:
Environment variables
For CI/CD pipelines and scripted environments, use environment variables instead of interactive login:
PowerShell:
CMD:
For guest access:
PowerShell:
CMD:
Environment variables take precedence over the configuration file and keyring.
Advanced authentication scenarios
Authentication inside TeamCity builds
When teamcity runs inside a TeamCity build, it automatically authenticates using build-level credentials from the build properties file. No additional configuration is required.
This allows you to use teamcity commands in build steps without storing or managing tokens:
Multiple servers
You can authenticate with several TeamCity servers. Each server's credentials are stored separately.
Adding servers
Switching between servers
There are several ways to target a specific server:
Environment variable (recommended for scripts):
PowerShell:
CMD:
Export for your session:
PowerShell:
CMD:
Log in again to change the default:
Server auto-detection from Kotlin DSL
When working in a project with TeamCity versioned settings, the CLI can detect the server URL from the Kotlin DSL pom.xml. It searches for .teamcity/ or .tc/ directories in the current folder and its parents (or uses TEAMCITY_DSL_DIR if set), and extracts the server URL from the DSL plugins repository URL. This auto-detected server URL is used when TEAMCITY_URL is not set. You still need credentials for that server.
Credential precedence
Server URL resolution order (highest priority first):
TEAMCITY_URLenvironment variableKotlin DSL auto-detection (
TEAMCITY_DSL_DIR,.teamcity/, or.tc/)default_serverfrom~/.config/tc/config.yml
Authentication resolution order (highest priority first):
Guest authentication (
TEAMCITY_GUESTor a server configured with guest access)TEAMCITY_TOKENenvironment variableStored token for the resolved server URL (system keyring first, then plain text config if
--insecure-storagewas used)Build-level credentials when running inside a TeamCity build