Overview
Thehc auth command group provides authentication management for the Harness CLI. These commands allow you to securely authenticate with Harness services, manage your credentials, and check your authentication status.
Authentication Storage
Credentials are stored securely in~/.harness/auth.json with restricted file permissions (0600). The authentication file contains:
- API Base URL
- Authentication Token
- Account ID
- Organization ID (optional)
- Project ID (optional)
The authentication token is stored locally and never transmitted except during API calls to Harness services.
Available Commands
login
Authenticate with Harness services and save credentials for future use. Supports both interactive and non-interactive modes.logout
Remove saved credentials and clear your authentication session.status
Check your current authentication status and verify credentials with the Harness API.Authentication Methods
Interactive Mode
When you runhc auth login without flags, the CLI enters interactive mode and prompts you for:
- API URL - The Harness API endpoint (defaults to
https://app.harness.io) - API Token - Your personal access token (input is hidden)
- Account ID - Automatically extracted from the token
- Organization ID - Optional scope for your session
- Project ID - Optional scope for your session
Non-Interactive Mode
For automation and CI/CD pipelines, use flags to provide credentials:Token Format
Harness API tokens follow the format:pat.{AccountID}.{Random}.{Random}
The CLI automatically extracts the Account ID from your token, so you typically don’t need to provide it separately in interactive mode.
Security Best Practices
- Store tokens as environment variables in CI/CD systems
- Use non-interactive mode for automation
- Regularly rotate your API tokens
- Use organization and project-scoped tokens when possible
- Run
hc auth logoutwhen switching accounts
Configuration Precedence
The CLI looks for credentials in the following order:- Command-line flags (e.g.,
--api-token) - Environment variables
- Saved authentication file (
~/.harness/auth.json)
Examples
First-time Setup
Switching Accounts
CI/CD Pipeline
Troubleshooting
Validation Failed
If credential validation fails during login:- Verify your token is valid and not expired
- Check that the API URL is correct
- Ensure your account ID matches the token
- Verify network connectivity to Harness services
Not Logged In
If commands report you’re not logged in:Permission Issues
If you encounter permission errors:Related Commands
After authenticating, you can use other Harness CLI commands:hc project- Manage projectshc pipeline- Manage pipelineshc service- Manage serviceshc secret- Manage secrets