Home DevOpsGitHub Actions Self-Hosted Runners on Linux: A Secure Setup Guide

GitHub Actions Self-Hosted Runners on Linux: A Secure Setup Guide

by Knowledge Base Linux
GitHub Actions Self-Hosted Runners on Linux — GitHub Actions Self-Hosted Runners on Linux: A Secure Setup Guide

Why GitHub Actions Self-Hosted Runners Deserve a Proper Setup – GitHub Actions Self-Hosted Runners on Linux

GitHub’s hosted runners are convenient — until you hit the monthly minute limits, need specialized hardware, or must build inside your own network where private registries and databases live. GitHub Actions self-hosted runners solve all three problems by letting your own Linux servers pick up workflow jobs. The catch: a carelessly installed runner is a permanent, trusted agent running on your infrastructure, listening for arbitrary code from your repositories. Security is not optional here. This article covers GitHub Actions Self-Hosted Runners on Linux in detail.

Workflow diagram showing a GitHub Actions self-hosted runner registering and listening for jobs on Linux

This guide walks you through installing GitHub Actions self-hosted runners on a Linux server the safe way: a dedicated unprivileged user, SHA-verified downloads, a short-lived registration token, systemd service installation with ./svc.sh, label-based job routing, and hardening notes including ephemeral runners and least privilege. All steps are verified against the current runner release flow documented by GitHub.

Prerequisites – GitHub Actions Self-Hosted Runners on Linux

You need a Linux server (Ubuntu 22.04 or 24.04 works well, but any systemd-based distro is fine) with sudo access, outbound HTTPS connectivity to github.com, and about 2 GB of free disk for the GitHub Actions self-hosted runners installation plus its work directories. You also need admin access to the GitHub repository (or organization) where the runner will be registered, because generating a registration token requires it. If you are new to GitHub Actions pipelines in general, our CI/CD pipeline with GitHub Actions and Docker guide covers the workflow side before you move to self-hosting the execution.

Step 1: Create a Dedicated Runner User

Never run a GitHub Actions self-hosted runner as root. The runner executes whatever code your workflows check out, so it should run as an unprivileged user with the minimum permissions its jobs need.

sudo useradd -m -s /bin/bash github-runner

This creates a github-runner user with its own home directory. If your jobs need Docker, add the user to the docker group — but understand that Docker socket access is effectively root-equivalent, so reserve it for GitHub Actions self-hosted runners you fully trust:

sudo usermod -aG docker github-runner

Install the tools your workflows will need (git, build essentials, Docker if applicable) before continuing:

sudo apt update && sudo apt install -y curl git tar

Step 2: Download and Verify the Runner Package

Find the latest release at github.com/actions/runner/releases, then download and extract it as the runner user. Verifying the SHA256 checksum is worth the extra step — you are installing software that will execute code on your server:

sudo -u github-runner -i
mkdir -p actions-runner && cd actions-runner

RUNNER_VERSION="2.335.1"
curl -o actions-runner-linux-x64-${RUNNER_VERSION}.tar.gz -L \
  https://github.com/actions/runner/releases/download/v${RUNNER_VERSION}/actions-runner-linux-x64-${RUNNER_VERSION}.tar.gz

# Verify checksum (get the expected hash from the release page)
echo "<expected-sha256>  actions-runner-linux-x64-${RUNNER_VERSION}.tar.gz" | sha256sum -c

tar xzf ./actions-runner-linux-x64-${RUNNER_VERSION}.tar.gz

Check the release notes on the releases page for the current version number and its published checksum before running these commands.

Step 3: Get a Registration Token

GitHub Actions self-hosted runners register with a short-lived token — it expires after about an hour and is single-use, so generate it right before you configure. In your repository, go to Settings > Actions > Runners, click New self-hosted runner, select Linux, and copy the token shown. For organization-level runners, the same screen lives under Organization settings > Actions > Runners.

Never paste this token into chat logs, tickets, or shared terminals. It grants the ability to attach a runner to your repository.

Step 4: Register the Runner with config.sh

Run the interactive configuration as the github-runner user, not as root. The --unattended flag skips prompts and is ideal for scripting:

./config.sh --url https://github.com/YOUR_ORG/YOUR_REPO \
  --token YOUR_REGISTRATION_TOKEN \
  --name "linux-runner-01" \
  --labels "self-hosted,linux,x64,ubuntu-24.04" \
  --work "_work" \
  --unattended

What each flag does:

--url scopes the runner to a repository or an organization. --name must be unique per runner — it is what you will see in the GitHub UI. --labels controls which jobs can target this machine; the self-hosted label is always applied automatically. --work sets the directory where job files are checked out (_work under the install directory by default). On success you will see “Connected to GitHub”, “Runner successfully added”, and “Settings Saved”.

For shared infrastructure, GitHub Actions self-hosted runners can also be registered at the organization level — one URL change (https://github.com/YOUR_ORG) plus an org registration token, and optionally --runnergroup to restrict which repositories may use it.

Step 5: Install GitHub Actions Self-Hosted Runners as a systemd Service

Running ./run.sh interactively is fine for a smoke test, but production runners must survive reboots and SSH disconnections. For systemd-based Linux, the runner ships with svc.sh for exactly this:

# Stop the interactive runner first if it is running
sudo ./svc.sh install github-runner
sudo ./svc.sh start

The install command takes an optional username argument — passing github-runner makes the service run as your dedicated user rather than root. Verify the service is healthy:

sudo ./svc.sh status
sudo systemctl status "actions.runner.*.service" --no-pager

You are looking for Active: active (running). To watch what the runner is doing, follow its logs:

sudo journalctl -u "actions.runner.*.service" -f

The line Listening for Jobs confirms the runner is registered and waiting. On Debian and Ubuntu systems with needrestart enabled, prevent it from restarting the runner mid-job by adding an ignore rule:

echo '$nrconf{override_rc}{qr(^actions\.runner\..+\.service$)} = 0;' | \
  sudo tee /etc/needrestart/conf.d/actions_runner_services.conf

The generated service name follows the pattern actions.runner.<org>-<repo>.<name>.service, and it is enabled at boot by the install step — exactly what you want for a build machine.

Step 6: Route Jobs to Your Runner with Labels

Jobs target GitHub Actions self-hosted runners through the runs-on key. Every label listed must match the runner:

jobs:
  build:
    runs-on: [self-hosted, linux, ubuntu-24.04]
    steps:
      - uses: actions/checkout@v4
      - name: Build project
        run: make build

Test with a minimal workflow, then check the repository’s Actions > Runners page to confirm your runner shows as online and idle after the job finishes.

Security Notes for GitHub Actions Self-Hosted Runners

GitHub Actions self-hosted runners deserve more caution than GitHub-hosted ones because they live on your network. Treat these as requirements, not suggestions.

Use ephemeral runners for untrusted code. Any workflow triggered by a fork pull request can execute attacker-controlled code on your runner. Register with --ephemeral so the runner handles exactly one job and then unregisters itself — combined with a fresh VM or container per run, this prevents persistence between jobs. Never run fork-PR workflows on persistent runners that also build your main branch.

Apply least privilege everywhere. The runner user should not have passwordless sudo, should not share credentials with other services on the host, and the registration token should never be baked into images or committed to repositories. Store tokens in a secrets manager and inject them at provisioning time.

Isolate runner hosts. Ideally, runners live on dedicated machines or VMs with no access to production databases, internal services, or other tenants’ data. Network segmentation and a host firewall that only allows outbound traffic to GitHub go a long way.

Keep the runner updated. GitHub periodically deprecates old runner versions. Enable automatic updates (the default behavior when the runner checks in) or schedule regular re-provisioning from your latest base image.

GitHub’s official documentation covers these topics in depth — start with docs.github.com: managing self-hosted runners and its security hardening guide.

Troubleshooting GitHub Actions Self-Hosted Runners

Runner shows offline in the GitHub UI. Check the systemd service first (sudo ./svc.sh status). If it is running but offline, the machine may have lost network connectivity to GitHub, or the runner version was retired — check journalctl for explicit errors.

Registration fails with a 401. The token expired (they last roughly an hour) or was already used. Generate a fresh token and re-run config.sh. If the runner was previously configured, remove it first with ./config.sh remove --token <token>.

Jobs never pick up the runner. The runs-on labels in the workflow must all match the runner’s label set. Note that self-hosted is mandatory in the match list — runs-on: linux alone will not find a self-hosted runner.

Permission denied on Docker or build tools. The github-runner user lacks group membership or file permissions. Add the user to the needed groups, log out and back in (group membership applies at login), and remember that the systemd service picks up groups from the user account at service start — restart the service after changes.

Runner dies after one job. That is the intended behavior of --ephemeral runners. If you did not ask for ephemeral mode, look for OOM kills or disk-full errors in the system journal — runners need headroom for artifact downloads and container layers.

Conclusion

GitHub Actions self-hosted runners give you unlimited build minutes, custom hardware, and private-network access — at the cost of owning the security model. The safe pattern is simple: dedicated unprivileged user, verified downloads, short-lived registration tokens, systemd management via ./svc.sh, label-based routing, and ephemeral runners wherever untrusted code might run. Compared with installing a traditional CI server like Jenkins (see our Jenkins on Ubuntu 24.04 guide), self-hosted runners keep your existing GitHub Actions workflows untouched while moving the compute to your own Linux fleet. Provision them with the same discipline you apply to any production server, and they will serve you reliably for years.

You may also like

KbLinux

Typically replies within a day

Hello, Welcome to the site. Please click below button for chatting me through Telegram.