LAYER 1 Perimeter · Firewall LAYER 2 Secrets · API Keys LAYER 3 Kill Switch · Execution
Layers reduce the chance that one failure exposes everything. A weakness in one layer does not automatically compromise the others, but no layer is a substitute for good operating practice at the layer behind it.

Operational Security for Trading VPS

Why Infrastructure Security Gets Neglected

Most retail algorithmic traders focus obsessively on strategy backtesting, overfitting, and regime detection. But when they finally deploy live, they often overlook the infrastructure that runs their strategy.

Result: a well-tuned algorithm running on a wide-open VPS, with API keys in config files, weak SSH credentials, no kill switches, and unmonitored resource exhaustion.

Two failure modes this article will not solve for you

The advice below assumes you have not yet exposed the server to the internet with weak settings. If you have already deployed with default SSH, default ports, and hardcoded secrets, treat this as a rebuild, not a patch:

  • Rotate every credential that has touched that host: SSH keys, exchange API keys, database passwords, Redis passwords, MT5 passwords.
  • Rebuild the VPS from a clean image. Do not try to clean an already-compromised box.
Illustrative composite

Attack escalation: how a small security oversight cascades

The sequence below is a composite of common failure modes. It is not a report of a specific incident.

  1. 1
    Password SSH on default port

    Weak credentials, no rate limiting, no key requirement.

  2. 2
    Scanner detects open service

    Automated scan finds port 22 responding with password auth enabled.

  3. 3
    Brute force succeeds

    Weak password falls after repeated attempts from rotating addresses.

  4. 4
    API keys stolen

    Exchange credentials found in an unencrypted config file.

  5. 5
    Unauthorised positions opened

    Leveraged orders placed overnight, without detection or alerting.

Real risk: what happens when you are compromised

  • API key theft: exchange API keys extracted from unencrypted configs; positions opened without authorisation.
  • Order manipulation: man-in-the-middle intercepts API calls, modifies order size or price.
  • Kill switch failure: strategy terminated maliciously; recovery takes time while the market moves against the position.
  • Data exfiltration: months of backtest data stolen; proprietary work exposed.

Security Is About Blast Radius

The goal is not perfect invulnerability - that is unrealistic. The goal is to reduce blast radius.

What experienced operators optimise for

  • Fast recovery instead of perfect prevention
  • Limited blast radius instead of single-point failure
  • Detection latency instead of reactive troubleshooting
  • Operational continuity during market stress
NIST SP 800-123 (2008). Guide to General Server Security.

Scarfone, K., Jansen, W., & Tracy, M. Foundational server hardening and operational security principles.

Download PDF | View Publication Page

Layer 1: Perimeter Defense

SSH Hardening: Disable Password Authentication

01

Password authentication

Brute-forceable

Attackers try common passwords, dictionaries, and rainbow tables against the SSH service. Weak passwords fall in minutes.

Result Breach
02

SSH key authentication

Cryptographic

Authentication uses a key pair. The private key never leaves the client. There is no password to guess.

Result Protected
Password authentication exposes the SSH service to guessable credentials. Key authentication removes that attack surface entirely - there is nothing to brute-force.

SSH is the primary attack surface. Default configuration allows password authentication - brute force attacks can compromise weak passwords in minutes. Disable password authentication entirely and use key-based authentication only.

Generate key pairssh-keygen -t ed25519 -C "trading-vps" -f ~/.ssh/id_trading_vps
/etc/ssh/sshd_config - critical modificationsPasswordAuthentication no PubkeyAuthentication yes Port 22222 PermitRootLogin no MaxAuthTries 3
Apply and reloadsudo sshd -t # validate the config before reloading sudo systemctl restart ssh # or: sudo systemctl reload ssh

Before you close your current session

  1. Open a second terminal and connect with the new port and key. Confirm the login works.
  2. Only then close your original session. If the new login fails and you have closed the old one, you may be locked out and need console access from your VPS provider.

Fail2ban: Ban Brute-Force Attackers

  1. 1
    Incoming attempts

    Repeated login attempts against the SSH service from a rotating set of IPs.

  2. 2
    Detection

    fail2ban reads the SSH auth log and matches failures against configured patterns.

  3. 3
    Threshold reached

    Five failures within ten minutes triggers the ban rule for that IP address.

  4. 4
    Ban applied

    iptables blocks traffic from the attacking IP for the configured duration.

  5. 5
    Server protected

    Brute-force attempts are throttled without human intervention. Targeted attacks need other defences.

5
Failed attempts threshold (common default)
10min
Default ban duration (stock fail2ban)
24hrs
If you set bantime = 24h
How fail2ban works: it monitors the SSH auth log in real time. When failures cross the configured threshold, it bans the source IP at the firewall level via iptables. The stock ban duration is 10 minutes. Extend it in jail.local if you want a longer block. fail2ban slows brute-force attacks; it does not stop targeted attacks from a determined adversary.
Install fail2bansudo apt-get update && sudo apt-get install -y fail2ban
/etc/fail2ban/jail.local - explicit 24-hour bans[DEFAULT] bantime = 24h findtime = 10m maxretry = 5 [sshd] enabled = true port = 22222

Firewall: UFW (Uncomplicated Firewall)

Order matters. If you enable UFW before allowing the new SSH port, you will lock yourself out.

Step 1 - allow your SSH port BEFORE enabling the firewallsudo ufw allow from YOUR_IP to any port 22222 proto tcp
Step 2 - set defaults and enablesudo ufw default deny incoming sudo ufw default allow outgoing sudo ufw enable sudo ufw status verbose

Confirm before disconnecting

Keep your current session open. In a second terminal, connect from the allowed IP. If the connection fails, disable UFW from the session still open (sudo ufw disable) and fix the rule before proceeding.

Layer 2: Secrets & Key Hygiene

Exchange API Keys

If an exchange or broker API key is stolen and it has withdrawal permission, the loss is not bounded by your strategy. Three controls apply regardless of how carefully the VPS is hardened:

Runtime Secrets: Environment Variables

Environment variables (Python)import os api_key = os.getenv("TRADING_API_KEY") if not api_key: raise RuntimeError("TRADING_API_KEY is not set")

The check matters. A missing variable that returns None silently will produce a live system that acts on empty credentials or fails to act when you expect it to.

MT5 Credentials

If you run an MT5 terminal on Windows, the broker login, password, and server are stored in config/*.ini and in the terminal's own data directory. These files are not encrypted. Treat the Windows host with the same standard as the VPS: full-disk encryption, automatic screen lock, and no shared-user accounts. Do not reuse the MT5 password anywhere else.

Backups

Configuration and audit logs should be backed up daily to storage outside the VPS. The backup target must be write-only from the VPS's perspective: if an attacker on the VPS can delete the backups, they are not backups. Use object storage with a scoped token and enable versioning.

OWASP. Secrets Management Cheat Sheet.

Recommends environment variables over hardcoded strings, encrypted storage, and rotation policies.

Read the OWASP Secrets Management Cheat Sheet

Layer 3: Kill Switch & Execution

The kill switch is a single point of control that can halt trading regardless of what the strategy decides. It should be the last thing that runs, and it should be safe when it cannot reach its backend.

Sketch - Redis-backed kill switch (not production code)import os import redis # decode_responses=True so the value compares as a string, not bytes. # Without this, "halt" != b"halt" and the switch silently no-ops. r = redis.Redis( host=os.getenv("REDIS_HOST", "127.0.0.1"), port=int(os.getenv("REDIS_PORT", 6379)), password=os.getenv("REDIS_PASSWORD"), # required in production decode_responses=True, socket_connect_timeout=1.0, ) # ties:kill_flag holds "pause", "halt" or "kill". # Missing key or unreachable Redis -> "run" (fail-open on read, # fail-safe on write: the trading loop is responsible for its own # circuit breakers if Redis is unreachable). try: state = r.get("ties:kill_flag") or "run" except redis.RedisError: state = "run" if state == "pause": pause_new_entries() elif state == "halt": close_all_positions() elif state == "kill": liquidate_all_positions()

Three things this snippet assumes and that you should verify in your own build:

Complete 20-Point Security Checklist

Printable PDF with scoring sheet, implementation tracker, and prioritisation guide. Audit your VPS against production-grade standards.

✓ SSH hardening checklist ✓ Secrets and key hygiene ✓ Kill switch verification

Request an Infrastructure Review

Scoped engineering and validation work for systematic traders and research teams. We review your SSH configuration, secrets handling, kill-switch design, and monitoring.

Initial 30-minute call at no charge Scoped engagements from $5,000/month Infrastructure review, not trade advice

Complete Security Checklist

20-Point VPS Security Checklist

  1. SSH: disable password auth, enable keys only
  2. Change default SSH port
  3. PermitRootLogin no
  4. MaxAuthTries 3
  5. Install fail2ban
  6. Configure fail2ban for custom SSH port and longer bantime
  7. UFW: allow your SSH port before enabling the firewall
  8. UFW: default deny incoming, allow SSH only from your IP
  9. Remove hardcoded credentials from config and compose files
  10. Use environment variables or a secrets manager
  11. .env file permissions 600
  12. Bind Postgres and Redis to 127.0.0.1, not all interfaces
  13. Set a Redis password; do not run unauthenticated Redis
  14. Exchange API keys: withdrawal permission disabled
  15. Exchange API keys: IP whitelisting enabled, 2FA on the account
  16. Prometheus metrics and Grafana alerts for anomalies
  17. Daily backups to write-only external storage with versioning
  18. Kill switch with explicit pause / halt / kill levels
  19. Monitor failed login attempts and kill switch state
  20. Incident response plan written down and rehearsed

Conclusion: Security Is Risk Management

The controls above cover the common failure modes for a single-VPS trading deployment. Most operate automatically once configured. Your strategy edge only matters if your infrastructure survives long enough to exploit it.

OWASP (2025). Secrets Management Cheat Sheet.

Read on OWASP

NIST SP 800-123 (2008). Guide to General Server Security.

Download PDF | View Publication Page

About the Author

Written by practitioners

Every system we build is validated in the open before it is offered externally. The full walk-forward record is published, including the windows that fail.

Alex Anyega

Alex Anyega

Founder & Head of Research

Solo founder. Quantitative researcher and software developer. Builds TIES from the ground up: research, software, and the validation infrastructure the research is measured against. No live capital record yet; the firm was incorporated in January 2026.

Quantitative Research Python Systems XAUUSD Strategy