*** title: CLI SSH Authentication (macOS) description: >- Resolve Brev CLI SSH authentication failures caused by invalid or corrupted SSH keys on macOS. ------------------ This guide helps you resolve Brev CLI authentication failures on macOS when SSH key issues prevent connection to your instances. **Platform**: macOS ## Problem On macOS systems, Brev CLI commands such as `brev ls`, `brev login`, or `brev ssh` fail with authentication or connection errors. **Typical symptoms include:** * `Permission denied (publickey)` * `Could not establish SSH connection` * `Error: connection closed unexpectedly` This issue occurs when the local SSH key used by Brev (`~/.brev/brev.pem`) becomes invalid, corrupted, or has incorrect file permissions. ## Prerequisites * macOS with Brev CLI installed (`brew install brevdev/homebrew-brev/brev`) * Access to Brev dashboard or web app * Terminal access with user home directory permissions ## Solution Choose one of the following approaches to resolve the issue. ### Option 1: Re-authenticate Using Token (Recommended) ### Open account settings Go to Brev Dashboard → Account Settings: [https://brev.nvidia.com/settings/account](https://brev.nvidia.com/settings/account) ### Navigate to CLI settings Click on **CLI** in the settings menu. ### Copy the token Copy the authentication token displayed on the page. ### Authenticate in terminal Paste the token in your terminal when prompted by: ```bash brev login --token ``` ### Verify connection ```bash brev ls ``` The command should list all available instances without error. ### Option 2: Regenerate SSH Key ### Check for existing Brev key ```bash ls -l ~/.brev/brev.pem ``` If the file is missing or has incorrect permissions, proceed to the next step. ### Backup and remove old key ```bash mv ~/.brev/brev.pem ~/.brev/brev.pem.bak ``` ### Generate a new Brev key 1. Go to the [Brev Dashboard](https://brev.nvidia.com) 2. Navigate to **Profile → SSH Keys** 3. Re-download or generate a new `.brev.pem` file ### Set correct file permissions ```bash chmod 600 ~/.brev/brev.pem ``` ### Re-authenticate with Brev ```bash brev login brev ls ``` Verify the connection is successful. ## Verification After completing either option: * `brev ls` lists all available instances without error * `brev ssh ` connects successfully to the instance * No permission or key errors appear in terminal output ## Workaround If key regeneration fails: * Temporarily use the [Brev Web Dashboard](https://brev.nvidia.com) for instance access * Restore the previous key if needed: ```bash mv ~/.brev/brev.pem.bak ~/.brev/brev.pem chmod 600 ~/.brev/brev.pem ```