---
title: "How do you use secrets in GitHub Actions?"  
description: "How do you use secrets in GitHub Actions?"  
author: "ICSM Computer"  
published: 2025-07-06  
updated: 2026-05-11  
canonical: https://www.mindstick.com/forum/161796/how-do-you-use-secrets-in-github-actions  
category: "GitHub"  
tags: ["github", "git"]  
reading_time: 2 minutes  

---

# How do you use secrets in GitHub Actions?

**How do you use secrets in GitHub Actions, [explain](https://www.mindstick.com/forum/157854/what-is-system-debugging-explain-some-system-debugging-tools-used-in-modern-computer-systems) with example**

## Replies

### Reply by ICSM Computer

You can use **Secrets** in GitHub Actions to securely store sensitive data like:

- API keys
- Database passwords
- Access tokens
- SSH keys
- Deployment credentials

## 1. Add a Secret in GitHub

Go to your repository:

[GitHub Repository Settings](https://github.com/settings/repositories)

Then:

- Open **Settings**
- Click **Secrets and variables** → **Actions**
- Click **New repository secret**

Add:

- Name → `API_KEY`
- Secret → your actual key

## 2. Use Secret in GitHub Actions Workflow

Example `.github/workflows/deploy.yml`

```plaintext
name: Deploy App

on:
  push:
    branches:
      - main

jobs:
  deploy:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Use Secret
        run: echo "API Key loaded successfully"

        env:
          API_KEY: ${{ secrets.API_KEY }}
```

## 3. Access Secret in Commands

```plaintext
- name: Call API
  run: curl -H "Authorization: Bearer $API_KEY" https://example.com
  env:
    API_KEY: ${{ secrets.API_KEY }}
```

## 4. Use Secrets in ASP.NET MVC / .NET Builds

```plaintext
- name: Build Application
  run: dotnet build
  env:
    ConnectionStrings__Default: ${{ secrets.DB_CONNECTION }}
```

In C#:

```plaintext
string connection =
    Environment.GetEnvironmentVariable("ConnectionStrings__Default");
```

## 5. Organization Secrets

If multiple repositories need the same secret:

- Organization Settings
- Secrets and variables
- Actions
- Create organization secret

Useful for:

- Shared deployment tokens
- Common API credentials
- CI/CD infrastructure keys

## 6. Important Security Rules

- Never hardcode secrets in code
- Never print secrets in logs
- Rotate secrets regularly
- Use least-privilege access tokens
- Prefer short-lived tokens when possible

## 7. Example: Deploy to Server via SSH

```plaintext
- name: Deploy via SSH
  uses: appleboy/ssh-action@v1.0.3
  with:
    host: ${{ secrets.SERVER_HOST }}
    username: ${{ secrets.SERVER_USER }}
    key: ${{ secrets.SERVER_SSH_KEY }}
    script: |
      cd /var/www/app
      git pull
      docker compose up -d
```

## 8. GitHub Encrypted Secrets vs Variables

| Feature | Secrets | Variables |
| --- | --- | --- |
| Encrypted | Yes | No |
| Sensitive data | Yes | No |
| Visible in logs | Masked | Visible |
| Best for | Passwords, tokens | App config |

## Official Documentation

[GitHub Actions Secrets Documentation](https://docs.github.com/en/actions/security-for-github-actions/security-guides/using-secrets-in-github-actions)

[GitHub Actions Documentation](https://docs.github.com/en/actions)


---

Original Source: https://www.mindstick.com/forum/161796/how-do-you-use-secrets-in-github-actions

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
