Usage
Description
Thehc auth logout command removes your saved Harness credentials by deleting the authentication configuration file located at ~/.harness/auth.json. This effectively ends your CLI session and clears all stored authentication data including API tokens, account IDs, and scope settings.
After logging out, you’ll need to run hc auth login again to authenticate with Harness services.
Flags
Force logout even if not currently logged in. When enabled, the command will succeed without error even if no authentication file exists.Useful for cleanup scripts or when you want to ensure a clean state regardless of current authentication status.
What Gets Removed
Runninghc auth logout performs the following actions:
- Deletes Authentication File - Removes
~/.harness/auth.jsonfrom disk - Clears Session Config - Resets global configuration values:
- API Base URL
- Authentication Token
- Account ID
- Organization ID
- Project ID
The command does not delete the
~/.harness directory itself, only the authentication file within it.Examples
Basic Logout
Standard logout when authenticated:Forced Logout
Force logout even when not authenticated:Logout Without Force
Attempting to logout when not authenticated (without--force):
Switch Between Accounts
Logout and login to a different account:Cleanup Script
Use in scripts to ensure clean authentication state:cleanup.sh
CI/CD Pipeline Cleanup
Clean up credentials after pipeline execution:Docker Container Cleanup
Ensure credentials don’t persist in containers:Dockerfile
entrypoint.sh
Error Handling
Not Logged In (Without Force)
When trying to logout without being authenticated:--force flag if you want the command to succeed anyway:
Permission Denied
If you encounter permission errors:Use Cases
Security Best Practice
Logout when finished working with Harness:Switching Environments
Switch between different Harness environments:Testing Multiple Accounts
Test CLI with different accounts:test-accounts.sh
Shared Machine Cleanup
On shared systems, always logout to protect your credentials:Verification
Confirm successful logout by checking:Check Authentication File
Try Authentication Status
Attempt API Operation
Comparison with Force Flag
| Scenario | Without --force | With --force |
|---|---|---|
| Logged in | Succeeds, removes auth file | Succeeds, removes auth file |
| Not logged in | Fails with error | Succeeds with message |
| File doesn’t exist | Fails with error | Succeeds with message |
| Permission denied | Fails with error | Fails with error |
Best Practices
- Always Logout on Shared Systems - Protect your credentials on multi-user machines
- Use in CI/CD Cleanup - Add logout to pipeline cleanup steps
- Force Flag in Scripts - Use
--forcein automation to avoid errors - Logout Before Switching - Always logout before logging into a different account
- Verify After Logout - Run
hc auth statusto confirm logout - Trap Signals - Use shell traps to ensure logout on script exit
- Container Cleanup - Always logout in Docker entrypoint cleanup
Security Implications
To fully secure your account:- Run
hc auth logout- Remove local credentials - Revoke the API token - Go to Harness UI and revoke the token if compromised
- Generate new token - Create a new token for future use
File Locations
| OS | Auth File Location |
|---|---|
| Linux | /home/username/.harness/auth.json |
| macOS | /Users/username/.harness/auth.json |
| Windows | C:\Users\username\.harness\auth.json |
Related Commands
- hc auth login - Authenticate with Harness
- hc auth status - Check authentication status
Troubleshooting
Logout Succeeds but File Still Exists
If the file still exists after logout:Can’t Logout Due to Process Lock
If another process is using the auth file:Directory Remains After Logout
The~/.harness directory is not deleted by logout: