Skip to content

Deploying Tabby self-hosted Copilot on Ubuntu 22.04 (production-ready)

Stand up a hardened Tabby code-completion server on Ubuntu 22.04 with NVIDIA + CUDA, GGUF models, systemd, repo indexing, nginx + Let's Encrypt, API tokens.

You’ve been asked to stand up a self-hosted Copilot alternative so the team stops shipping function bodies to a third-party SaaS. Tabby’s quickstart works on your workstation, the IDE plugin connects, completions come back in under a second, you hand it over. Six months later the GPU is OOM on a long-context prompt because nobody capped the model size to the VRAM, the /v1/completions endpoint is open to the public internet because the readme example bound 0.0.0.0:8080 and nginx was an afterthought, a repo with .env files got indexed because the indexer ignored your .gitignore, and an unauthenticated scraper is pulling completion logs that contain proprietary code from the trace endpoint.

What’s happening

A Tabby deployment that is actually production-ready needs more than tabby serve. The model has to fit VRAM with the chosen context window — a 7B GGUF Q4 fits in ~5 GB but a 13B Q4 at 8K context wants ~10 GB, and OOM mid-completion takes the whole worker down. The HTTP listener has to bind 127.0.0.1 behind nginx terminating TLS on a real Let’s Encrypt cert; the Authorization: Bearer token has to be required on every request including the metrics endpoint. The repo indexer has to honour .gitignore plus a dedicated .tabbyignore so .env, *.pem, id_rsa*, secrets in fixtures, and customer data dumps never become retrieval context. CUDA toolkit version has to match the driver, otherwise the daemon falls back to CPU at 30+ s per completion and looks broken to every IDE in the office. None of these are individually critical — skip them and the code-completion service either leaks secrets, gets scraped, or just plain doesn’t work under load.

How to verify

After install, GPU presence and CUDA visibility:

nvidia-smi
# Driver Version: 535.xx  CUDA Version: 12.2
# 0  NVIDIA L4   ...  14000MiB / 23034MiB

The HTTP listener must be on 127.0.0.1, never 0.0.0.0:

ss -lntp | grep -E ':(8080|443)\b'
# 127.0.0.1:8080  tabby
# 0.0.0.0:443     nginx

Round-trip a real completion through nginx with the API token:

curl -fsS -X POST https://tabby.example.com/v1/completions \
  -H "Authorization: Bearer ${TABBY_TOKEN}" \
  -H "Content-Type: application/json" \
  -d '{"language":"python","segments":{"prefix":"def fib(n):\n    "}}' \
  | jq -r '.choices[0].text' | head -5

If that round-trip times out, a request without the token returns 200 instead of 401, or nvidia-smi shows the worker on CPU, you’ve got a problem before the first IDE plugin connects.

The fix

Save the script below as /root/setup-tabby-ubuntu22.sh, then run it. It runs the installer flow on a fresh Ubuntu 22.04 VM: base update, kernel tuning, file limits, UFW (SSH + HTTP + HTTPS only), SSH hardening, unattended-upgrades, NVIDIA driver + CUDA toolkit (only if a GPU is detected), Tabby binary install with the cuda feature, a dedicated tabby system user, model directory at /var/lib/tabby with the StarCoder2-3B GGUF for completion and a Qwen2.5-Coder-1.5B GGUF for chat, a .tabbyignore template that excludes secret-prone paths, a systemd unit with LimitNOFILE=64000 and the API token in an env file (mode 600), nginx with TLS termination and the Authorization header passed through, Let’s Encrypt via certbot, and a poll loop that waits for the :8080 upstream before declaring success.

#!/usr/bin/env bash
set -euo pipefail

### Ubuntu 22.04 Tabby clean VM installer
### Keeps root SSH key login enabled
### Disables SSH password login
### Enables automatic security updates
### Installs NVIDIA driver + CUDA (if GPU present), Tabby, nginx, Let's Encrypt
### No local backups; assumes VM-level backup. Model weights re-downloadable from upstream.
### Reboot remains manual

if [[ "$(id -u)" -ne 0 ]]; then
  echo "Run as root."
  exit 1
fi

: "${TABBY_DOMAIN:?Set TABBY_DOMAIN=tabby.example.com}"
: "${TABBY_EMAIL:?Set TABBY_EMAIL=ops@example.com for Let's Encrypt}"
TABBY_VERSION="${TABBY_VERSION:-0.18.0}"
TABBY_TOKEN="${TABBY_TOKEN:-$(openssl rand -hex 32)}"
TABBY_MODEL="${TABBY_MODEL:-StarCoder2-3B}"
TABBY_CHAT_MODEL="${TABBY_CHAT_MODEL:-Qwen2.5-Coder-1.5B-Instruct}"

echo
echo "========================================"
echo "Tabby Ubuntu 22.04 Setup"
echo "========================================"
echo

echo "==> Updating base OS"
export DEBIAN_FRONTEND=noninteractive
apt-get update
apt-get -y upgrade

echo "==> Installing base packages"
apt-get -y install \
  vim curl wget ca-certificates gnupg2 \
  chrony fail2ban unattended-upgrades \
  ufw lsof tcpdump dnsutils tar gzip \
  iproute2 net-tools openssl jq \
  build-essential pkg-config libssl-dev \
  git software-properties-common

echo "==> Enabling time sync"
systemctl enable --now chrony
timedatectl set-ntp true

echo "==> Applying kernel/network tuning"
cat > /etc/sysctl.d/99-tabby.conf <<'SYSCTL'
net.core.default_qdisc = fq
net.ipv4.tcp_congestion_control = bbr

net.core.somaxconn = 4096
net.core.netdev_max_backlog = 250000
net.ipv4.tcp_max_syn_backlog = 8192
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_fin_timeout = 15
net.ipv4.ip_local_port_range = 10240 65535

net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.default.accept_redirects = 0
net.ipv6.conf.all.accept_redirects = 0
net.ipv6.conf.default.accept_redirects = 0

kernel.dmesg_restrict = 1
kernel.kptr_restrict = 2
fs.file-max = 2097152
SYSCTL

modprobe tcp_bbr || true
echo tcp_bbr > /etc/modules-load.d/bbr.conf
sysctl --system

echo "==> Setting file limits"
cat > /etc/security/limits.d/99-tabby.conf <<'LIMITS'
* soft nofile 64000
* hard nofile 64000
root soft nofile 64000
root hard nofile 64000
LIMITS

echo "==> Configuring UFW"
ufw --force reset
ufw default deny incoming
ufw default allow outgoing
ufw allow 22/tcp
ufw allow 80/tcp
ufw allow 443/tcp
ufw --force enable

echo "==> Hardening SSH while keeping root SSH key login enabled"
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak.$(date +%F-%H%M%S)

set_sshd_option() {
  local key="$1"
  local value="$2"
  if grep -qE "^[#[:space:]]*${key}[[:space:]]+" /etc/ssh/sshd_config; then
    sed -i "s|^[#[:space:]]*${key}[[:space:]].*|${key} ${value}|" /etc/ssh/sshd_config
  else
    echo "${key} ${value}" >> /etc/ssh/sshd_config
  fi
}

set_sshd_option PermitRootLogin prohibit-password
set_sshd_option PasswordAuthentication no
set_sshd_option PubkeyAuthentication yes
set_sshd_option KbdInteractiveAuthentication no
set_sshd_option ChallengeResponseAuthentication no
set_sshd_option X11Forwarding no
set_sshd_option ClientAliveInterval 300
set_sshd_option ClientAliveCountMax 2
set_sshd_option MaxAuthTries 4

sshd -t
systemctl restart ssh

echo "==> Configuring fail2ban"
mkdir -p /etc/fail2ban/jail.d
cat > /etc/fail2ban/jail.d/sshd.local <<'FAIL2BAN'
[sshd]
enabled = true
port = ssh
backend = systemd
maxretry = 4
findtime = 10m
bantime = 1h
FAIL2BAN

systemctl enable --now fail2ban

echo "==> Configuring unattended-upgrades for security"
cat > /etc/apt/apt.conf.d/20auto-upgrades <<'AUTOUPG'
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";
APT::Periodic::AutocleanInterval "7";
AUTOUPG

echo "==> Detecting GPU"
GPU_PRESENT=0
if command -v lspci >/dev/null 2>&1; then
  if lspci | grep -i nvidia >/dev/null 2>&1; then
    GPU_PRESENT=1
  fi
else
  apt-get -y install pciutils
  if lspci | grep -i nvidia >/dev/null 2>&1; then
    GPU_PRESENT=1
  fi
fi

if [[ "$GPU_PRESENT" -eq 1 ]]; then
  echo "==> NVIDIA GPU detected — installing driver + CUDA 12.2"
  apt-get -y install linux-headers-$(uname -r)
  wget -qO /tmp/cuda-keyring.deb \
    https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-keyring_1.1-1_all.deb
  dpkg -i /tmp/cuda-keyring.deb
  apt-get update
  apt-get -y install cuda-toolkit-12-2 nvidia-driver-535
  cat > /etc/profile.d/cuda.sh <<'CUDAENV'
export PATH=/usr/local/cuda/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
CUDAENV
  ldconfig
else
  echo "==> No NVIDIA GPU detected — Tabby will run on CPU (not recommended for production)."
fi

echo "==> Creating tabby system user and directories"
if ! id tabby >/dev/null 2>&1; then
  useradd --system --home /var/lib/tabby --shell /usr/sbin/nologin tabby
fi
mkdir -p /var/lib/tabby /var/log/tabby /etc/tabby
chown -R tabby:tabby /var/lib/tabby /var/log/tabby
chmod 750 /var/lib/tabby /var/log/tabby

echo "==> Downloading Tabby ${TABBY_VERSION} (cuda build)"
TABBY_TARBALL="tabby_x86_64-manylinux2014-cuda122.zip"
if [[ "$GPU_PRESENT" -eq 0 ]]; then
  TABBY_TARBALL="tabby_x86_64-manylinux2014.zip"
fi

cd /tmp
wget -qO tabby.zip \
  "https://github.com/TabbyML/tabby/releases/download/v${TABBY_VERSION}/${TABBY_TARBALL}"
apt-get -y install unzip
unzip -o tabby.zip -d /tmp/tabby-bin
install -m 0755 /tmp/tabby-bin/tabby /usr/local/bin/tabby

echo "==> Writing .tabbyignore template (keep secrets out of the index)"
cat > /var/lib/tabby/.tabbyignore <<'TABBYIGNORE'
# Tabby repo indexer ignore list — keep secrets out of completion context
.env
.env.*
*.pem
*.key
*.p12
*.pfx
id_rsa
id_rsa.*
id_ed25519
id_ed25519.*
known_hosts
**/secrets/**
**/credentials/**
**/.aws/**
**/.gcp/**
**/.kube/**
**/node_modules/**
**/vendor/**
**/dist/**
**/build/**
**/.git/**
**/__pycache__/**
**/*.log
**/fixtures/secrets/**
TABBYIGNORE

chown tabby:tabby /var/lib/tabby/.tabbyignore
chmod 640 /var/lib/tabby/.tabbyignore

echo "==> Writing Tabby env file"
cat > /etc/tabby/tabby.env <<ENV
TABBY_TOKEN=${TABBY_TOKEN}
TABBY_MODEL=${TABBY_MODEL}
TABBY_CHAT_MODEL=${TABBY_CHAT_MODEL}
TABBY_ROOT=/var/lib/tabby
RUST_LOG=info
ENV

chmod 600 /etc/tabby/tabby.env
chown root:tabby /etc/tabby/tabby.env

echo "==> Writing Tabby systemd unit"
DEVICE_FLAG="--device cuda"
if [[ "$GPU_PRESENT" -eq 0 ]]; then
  DEVICE_FLAG=""
fi

cat > /etc/systemd/system/tabby.service <<UNIT
[Unit]
Description=Tabby self-hosted code completion server
After=network-online.target
Wants=network-online.target

[Service]
Type=simple
User=tabby
Group=tabby
EnvironmentFile=/etc/tabby/tabby.env
WorkingDirectory=/var/lib/tabby
ExecStart=/usr/local/bin/tabby serve \\
  --model \${TABBY_MODEL} \\
  --chat-model \${TABBY_CHAT_MODEL} \\
  ${DEVICE_FLAG} \\
  --host 127.0.0.1 \\
  --port 8080
Restart=on-failure
RestartSec=10
LimitNOFILE=64000
NoNewPrivileges=true
ProtectSystem=full
ProtectHome=true
PrivateTmp=true

[Install]
WantedBy=multi-user.target
UNIT

systemctl daemon-reload
systemctl enable --now tabby

echo "==> Waiting for Tabby on 127.0.0.1:8080 (first run downloads model weights)"
for i in {1..180}; do
  if ss -lntp | grep -q '127.0.0.1:8080'; then
    break
  fi
  sleep 2
done

if ! ss -lntp | grep -q '127.0.0.1:8080'; then
  echo "Tabby failed to listen on 127.0.0.1:8080"
  journalctl -u tabby -n 200 --no-pager || true
  exit 1
fi

echo "==> Installing nginx and certbot"
apt-get -y install nginx certbot python3-certbot-nginx

cat > /etc/nginx/sites-available/tabby <<NGINX
upstream tabby_backend {
    server 127.0.0.1:8080;
    keepalive 32;
}

server {
    listen 80;
    listen [::]:80;
    server_name ${TABBY_DOMAIN};
    return 301 https://\$host\$request_uri;
}

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name ${TABBY_DOMAIN};

    client_max_body_size 10M;
    proxy_read_timeout   300s;
    proxy_send_timeout   300s;
    proxy_connect_timeout 60s;

    add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
    add_header X-Content-Type-Options nosniff always;
    add_header X-Frame-Options SAMEORIGIN always;
    add_header Referrer-Policy strict-origin-when-cross-origin always;

    location / {
        proxy_set_header Host \$host;
        proxy_set_header X-Real-IP \$remote_addr;
        proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto \$scheme;
        proxy_set_header Authorization \$http_authorization;
        proxy_http_version 1.1;
        proxy_pass http://tabby_backend;
    }
}
NGINX

ln -sf /etc/nginx/sites-available/tabby /etc/nginx/sites-enabled/tabby
rm -f /etc/nginx/sites-enabled/default

nginx -t
systemctl enable --now nginx
systemctl reload nginx

echo "==> Requesting Let's Encrypt certificate"
certbot --nginx --non-interactive --agree-tos \
  -m "${TABBY_EMAIL}" -d "${TABBY_DOMAIN}" --redirect

systemctl enable --now certbot.timer

echo "==> Final package update"
apt-get -y upgrade

echo
echo "========================================"
echo "DONE"
echo "========================================"
echo
echo "Kernel:"
uname -r

echo
if [[ "$GPU_PRESENT" -eq 1 ]]; then
  echo "GPU:"
  nvidia-smi -L || true
else
  echo "GPU: not present (CPU mode)"
fi

echo
echo "Listeners:"
ss -lntp | grep -E ':(80|443|8080)\b' || true

echo
echo "Services:"
systemctl is-active tabby nginx fail2ban chrony || true

echo
echo "API token (store in your secrets manager, then remove /etc/tabby/tabby.env from disk):"
echo "${TABBY_TOKEN}"

echo
echo "IDE plugin endpoint:"
echo "https://${TABBY_DOMAIN}/"

echo
echo "Smoke test:"
echo "curl -fsS -X POST https://${TABBY_DOMAIN}/v1/completions \\"
echo "  -H 'Authorization: Bearer ${TABBY_TOKEN}' \\"
echo "  -H 'Content-Type: application/json' \\"
echo "  -d '{\"language\":\"python\",\"segments\":{\"prefix\":\"def fib(n):\\n    \"}}'"

echo
echo "Next steps:"
echo "1) Install the Tabby IDE plugin (VS Code, JetBrains, Vim) — set endpoint to https://${TABBY_DOMAIN}/ and paste the API token."
echo "2) Review /var/lib/tabby/.tabbyignore before adding repos via the admin UI — secrets must be excluded."
echo "3) Rotate TABBY_TOKEN out of /etc/tabby/tabby.env into your secrets manager."

Make it executable and run it:

chmod 700 /root/setup-tabby-ubuntu22.sh
TABBY_DOMAIN=tabby.example.com TABBY_EMAIL=ops@example.com /root/setup-tabby-ubuntu22.sh

First start downloads the GGUF weights into /var/lib/tabby/models — expect a few minutes before :8080 comes up. Once the listener is live, install the Tabby plugin in VS Code or JetBrains, point it at https://tabby.example.com/ with the bearer token, and run the smoke curl from the verify section. Before adding any repo through the admin UI, review /var/lib/tabby/.tabbyignore — completion context is whatever the indexer reads, so a stray .env becomes an autocomplete suggestion. The script intentionally does not configure host-level backups — model weights are re-downloadable from upstream and the repo index is rebuildable, so VM-level snapshots are enough for disaster recovery.

Run the production code-AI on a Stack Harbor-managed GPU environment with VRAM headroom, patch cadence, and Sev-1 escalation: GPU cloud compute.