Skip to content
Mchael Poncardas
Go back

Secure API Key Management for AI Tools

2 min read

When setting up AI tools like MCP servers, you often need to store sensitive API keys as environment variables. Here is the most practical way to do it for Bash/Zsh and Fish shell.

1. For Zsh or Bash (.zshrc / .bashrc)

Most macOS users (on Zsh) or Linux users (on Bash) store variables in a hidden configuration file. These files are read every time a new terminal window opens.

  1. Open your config file:

    • Zsh: nano ~/.zshrc
    • Bash: nano ~/.bash_profile (or ~/.bashrc)
  2. Add your key at the bottom:

    export GITHUB_MCP_PAT="ghp_your_token_here"
    export CONTEXT7_API_KEY="c7_your_key_here"
  3. Save and Exit: Press Ctrl+O, Enter, then Ctrl+X.

  4. Activate changes: Run source ~/.zshrc (or restart your terminal).

2. For Fish Shell (Universal Variables)

Fish shell handles things differently. Instead of editing a text file, you can set a Universal Variable directly in the command line. This is cleaner and more secure.

  1. Run the command once:

    set -Ux GITHUB_MCP_PAT ghp_your_token_here
    set -Ux CONTEXT7_API_KEY c7_your_key_here
  2. Why this is better:

    • Persistence: It survives restarts without needing a “source” command.
    • No File Bloat: It is stored in Fish’s internal database, not in your config.fish text file.
    • Security: If you share your config.fish online, your api keys stay hidden.

Summary Table

FeatureZsh / BashFish (Universal)
StoragePlain text file (.zshrc)Internal binary database
Commandexport KEY="value"set -Ux KEY value
Requires Restart?Yes (or source)No (immediate)
Best for DotfilesManual managementAutomatic isolation

Never commit your .zshrc or config.fish to a public GitHub repository if you have written your API keys directly into them.

Share this post on:

Related Posts


Next Post
How to Sync Custom Fonts in Obsidian Across All Your Devices