How to Secure and Install Claude Code via SSH
@Claude mentions), a separate and simpler integration. The custom Express bridge in this guide is still useful for platforms without an official channel yet, or for teams that need full control over the request path.Claude Code is a command-line coding agent that can read your files, run commands, and make changes on its own. That's powerful on a laptop where you're watching every step — it's a different story on a server that's also taking requests from Slack, Telegram, or Discord. Before you wire messaging platforms into a live agent, you need real isolation: a locked-down user account, a proxy that terminates TLS, and validation on every incoming request. This guide walks through that setup end to end.
Operating System Compatibility & Requirements
Claude Code ships as a native binary for macOS, Windows, and Linux. It runs best on Unix-like systems since it's built around interacting directly with the shell, the filesystem, and dev tools like compilers and Git. One thing worth clearing up: you don't need Node.js installed to run Claude Code. That's only a requirement if you install it through npm instead of the native installer — more on that in Step 4.
System Requirements
Here's what Anthropic actually documents as requirements for running Claude Code:
| Resource | Requirement |
|---|---|
| Operating System | Ubuntu 20.04+, Debian 10+, or Alpine Linux 3.19+ (this guide uses Ubuntu LTS) |
| Processor | x64 or ARM64 |
| Memory (RAM) | 4 GB or more |
| Network | Active internet connection to reach Anthropic's API |
| Node.js (npm install only) | Node.js 22 or later — not required if using the native installer |
There's no published minimum for disk space or CPU cores — size your VPS based on what your workload actually needs.
Prerequisites
Before you get started, make sure you have:
- A Self-Managed VPS or VDS Instance running an active Ubuntu LTS configuration.
- An Active Anthropic API Key configured with sufficient billing limits.
- A Domain Name with an A record mapped directly to your VPS IP to provision automated HTTPS.
Step 1: Connect to Your VPS via SSH
Start by connecting to your server so you can run the setup commands directly.
- Open a terminal on your local machine.
- Connect over SSH, swapping in your VPS's actual IP address:
- Log in with your credentials. You should land at a root prompt:
Step 2: Harden the Linux Host
Security starts at the OS level, before Claude Code ever enters the picture. A few basic steps here go a long way toward keeping automated scans and brute-force attempts out.
Install a Text Editor
Minimal cloud server images often skip basic tools like a text editor. Update your package list and install nano:
Example Output:
Create a Non-Root User
Letting an automated agent run commands as root is asking for trouble. Create a dedicated, unprivileged user to run Claude Code and the bridge process instead:
Add it to the sudo group so it can still run administrative commands when needed:
Switch to Key-Based SSH Authentication
Open the SSH daemon config file:
Update these lines to turn off password logins and root login entirely, so only SSH keys work:
Save the file (Ctrl+O, then Enter, then Ctrl+X) and restart SSH so the changes take effect:
Set Up the Firewall
Claude Code reaches out to Anthropic's API over outbound connections, and your bridge will need inbound web traffic for the webhook. Everything else should stay closed. Here's a basic UFW setup for that:
Install Fail2Ban
Fail2Ban watches for repeated failed login attempts and bans the source automatically. Install it:
Enable it so it starts on boot:
From here on, switch to the claudeadmin user you created and run the rest of the steps from there:
Example Output:
Step 3: Install Node.js (Optional)
Skip this step if you're using the native installer in Step 4 — it doesn't need Node.js at all. Only come back to this if you decide to install Claude Code via npm instead, or if other tools in your workspace depend on Node. Here's how to get a current version from NodeSource:
Check that both installed correctly:
Step 4: Install Claude Code
The native installer is the simplest route — it doesn't touch Node.js at all:
Check that it installed correctly:
Alternative: Install via npm
If you'd rather manage Claude Code through npm alongside your other global packages, that works too. Just skip sudo here — running npm installs as root tends to cause permission headaches down the line:
This route needs Node.js 22 or newer. If you set up Node in Step 3, double-check the version first:
Step 5: Set Up Your Workspace
Decide how much isolation you need before you start wiring up messaging platforms.
Option A: A Plain Git Workspace
For most setups, a simple Git-tracked directory works fine. Claude Code uses Git to understand project boundaries:
Option B: A Sandboxed Container Workspace
If your webhook is going to accept requests from people you don't fully trust, run Claude Code inside a container instead of directly on the host:
Step 6: Add Your API Key
Claude Code needs your Anthropic API key available in the environment. Open your shell config:
Add this line to the bottom of the file, with your actual key:
Then reload your shell so the change takes effect:
Step 7: Build the Webhook Bridge
Claude Code is built as an interactive CLI tool — it doesn't listen for web requests on its own. To connect it to Slack, Telegram, or Discord, you need a small server sitting in front of it that validates incoming webhooks, pulls out the message, runs Claude Code in non-interactive mode (-p), and sends the result back.
- Create a directory for the bridge and install dependencies:
- Create the main server file:
- Paste in the following:
- Create a
.envfile:
- Add your port and a long, random secret — this is what verifies incoming webhooks:
- Start the bridge. For anything beyond quick testing, run it under a process manager like
pm2or a systemd service so it survives reboots and crashes — a bare background process won't:
Step 8: Put Caddy in Front of Your Bridge
You don't want to expose port 3000 directly to the internet. Caddy handles TLS certificates automatically and proxies requests to your bridge over HTTPS.
- Install Caddy:
- Edit Caddyfile to map your domain address:
Insert your configuration block (replace domain accordingly):
- Restart Caddy. It'll automatically request a Let's Encrypt certificate for your domain:
Step 9: Connect Your Messaging Platform
Your webhook is now live at https://claude.yourdomain.com/webhook/claude. Pick the platform you want to connect:
@Claude mentions) may get you there without building anything. The steps below are for platforms without an official channel yet, or if you need more control over the request path than those options give you.Scenario A: Slack Workspace Commands
- Go to Slack API App Management Dashboard, create a new App.
- Select Slash Commands and create a new command.
- Configure the trigger (e.g.
/claude) and set Request URL to your public proxy endpoint. - Copy your App's Signing Secret and update
MESSENGER_SECRETin your bridge's.env. - Refer to Slack Bolt Integration Docs.
Scenario B: Telegram Private Automation Bots
- Use
@BotFatherin Telegram and send/newbot. - Follow prompts to receive your Bot Token.
- Bind webhook with curl:
- See Telegram Webhook Bot API Documentation for details.
Scenario C: Discord Application Interactions
- Access Discord Developer Portal, create an app.
- Enable Bot and message gateway permissions.
- Paste endpoint URL in Interactions Endpoint URL box.
- Refer to Discord Interactions Security Guide.
Summary
With key-based SSH, a non-root user running the agent, a signature-verified webhook bridge, and Caddy handling TLS in front of it, you've got a reasonably hardened setup for running Claude Code behind a messaging platform. Keep an eye on Anthropic's official Channels feature as it matures — it may eventually replace the custom bridge here for supported platforms.