MyCloudAlly
Guide · Ubuntu 24.04 · Facts checked November 2026

How to run Claude Code 24/7 on a VPS (and reach it from your phone)

TL;DR: Rent an Ubuntu 24.04 VPS with at least 4 GB of RAM, lock it down, install Claude Code with the official installer, and log in with claude auth login. Run it inside tmux under a systemd service so it survives disconnects and reboots, then steer it from the Claude mobile app with Remote Control. Expect about an hour of setup plus ongoing maintenance.

Claude Code is happiest on a machine that never sleeps. A VPS gives it a persistent filesystem, long-running processes, and a public IP, and with Anthropic's Remote Control feature you can pick up the session from your phone. This guide is the full, honest path, including the parts other tutorials skip: least-privilege users, auth that survives a headless box, and the gotchas that break "always-on." Every command targets Ubuntu 24.04 and every Claude Code flag comes from Anthropic's official docs.

What size VPS does Claude Code need?

Anthropic's system requirements list 4 GB+ RAM, an x64 or ARM64 processor, and Ubuntu 20.04+ or Debian 10+. Treat 4 GB as the floor: the agent will also run your builds, dev servers and databases. Two vCPUs and 40 GB of disk is a comfortable start.

Price-wise, a 4 GB / 2 vCPU Basic droplet is $24/mo on DigitalOcean, while budget European hosts like Hetzner list 4 GB plans in the single-digit euros (Hetzner adjusted prices in 2026, so check before you buy). Add your SSH public key when you create the server.

How do I set up users and SSH keys safely?

You'll make two accounts: one for you (with sudo), and one for the agent (without sudo). Claude Code runs shell commands, so the account it runs as defines how much damage a bad command can do. First, on your laptop, create a key if you don't have one:

ssh-keygen -t ed25519 -C "laptop"
ssh-copy-id root@YOUR_SERVER_IP   # skip if you added the key at creation

Then, logged in as root on the server:

apt update && apt upgrade -y
adduser you                                  # your admin login (pick a password)
usermod -aG sudo you
rsync --archive --chown=you:you ~/.ssh /home/you
adduser --disabled-password --gecos "" claude   # the agent's user: no sudo, no password

Open a second terminal and confirm ssh you@YOUR_SERVER_IP works before going further. Then disable root and password logins. On Ubuntu 24.04, cloud images often ship a 50-cloud-init.conf drop-in, and sshd keeps the first value it reads, so name your file so it sorts first:

sudo tee /etc/ssh/sshd_config.d/00-hardening.conf >/dev/null <<'EOF'
PermitRootLogin no
PasswordAuthentication no
KbdInteractiveAuthentication no
EOF
sudo sshd -t && sudo systemctl restart ssh

Which firewall rules does it need?

Only SSH. Remote Control makes outbound HTTPS requests only and never opens inbound ports, so you don't need to expose anything for phone access. Open 80/443 later only if you host web apps.

sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow OpenSSH
sudo ufw enable
sudo apt install -y fail2ban unattended-upgrades
sudo systemctl enable --now fail2ban
sudo fail2ban-client status sshd
sudo dpkg-reconfigure --priority=low unattended-upgrades

Add swap too. It's cheap insurance against the out-of-memory kills that silently end long agent sessions:

sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

How do I install Claude Code (and do I need Node.js)?

You don't need Node for Claude Code itself. The recommended native installer ships a standalone binary to ~/.local/bin/claude and auto-updates in the background. (The npm package still exists, but it needs Node.js 22+, and Anthropic warns never to install it with sudo.) Install the basics as your admin user, then switch to the agent user:

sudo apt install -y git tmux curl unzip
sudo -iu claude
curl -fsSL https://claude.ai/install.sh | bash
exit
sudo -iu claude          # log in again so ~/.local/bin is on PATH
claude --version
claude doctor

If your projects need Node (most web apps do), install an LTS build system-wide from your admin account, for example via NodeSource:

curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt install -y nodejs

How do I log in to Claude Code on a headless server?

Claude Code requires a Pro, Max, Ultra, Team, Enterprise or Console account; the free plan doesn't include it. On a box without a browser, the login flow prints a URL. Open it on your laptop or phone, approve, and paste the code back at the Paste code here if prompted prompt:

claude auth login
claude auth status --text

Credentials land in ~/.claude/.credentials.json with mode 0600. Two things matter for always-on use:

How do I keep Claude Code running after I disconnect?

Anthropic's own docs say it: on a remote machine, start Claude inside tmux or screen so it keeps running after SSH drops. As the claude user:

mkdir -p ~/projects/myapp && cd ~/projects/myapp && git init
tmux new -s work
claude
# detach with Ctrl-b then d; later, reattach with:
tmux attach -t work

How do I make it start on boot with systemd?

tmux survives disconnects, not reboots or crashes. For that, run Claude Code's Remote Control server mode (claude remote-control) from a systemd service. Server mode needs a terminal for its first-run prompts, so run it once by hand first in the project directory and answer y to the workspace-trust and "Enable Remote Control?" questions, then press Ctrl-C:

cd ~/projects/myapp
claude remote-control --name "my-vps"

Back in your admin account, create the service. It runs tmux on its own socket (-L rc) so it never collides with your interactive tmux, and gives server mode the terminal it expects:

sudo tee /etc/systemd/system/claude-rc.service >/dev/null <<'EOF'
[Unit]
Description=Claude Code Remote Control server (in tmux)
After=network-online.target
Wants=network-online.target

[Service]
Type=forking
User=claude
WorkingDirectory=/home/claude/projects/myapp
Environment=PATH=/home/claude/.local/bin:/usr/local/bin:/usr/bin:/bin
ExecStart=/usr/bin/tmux -L rc new-session -d -s rc 'claude remote-control --name my-vps'
ExecStop=/usr/bin/tmux -L rc kill-server
Restart=always
RestartSec=15

[Install]
WantedBy=multi-user.target
EOF
sudo systemctl daemon-reload
sudo systemctl enable --now claude-rc
systemctl status claude-rc

To peek at it: sudo -iu claude tmux -L rc attach -t rc. Restart=always matters because server mode gives up and exits after roughly 10 minutes without network; systemd brings it back.

How do I control Claude Code on my VPS from my phone?

Option 1: Remote Control (official)

Remote Control connects the Claude app for iOS and Android, or claude.ai/code, to the session running on your server. In the app, tap Code and pick your session (online sessions show a green dot). Code runs on your VPS; the app is a window into it. It works on Pro, Max, Ultra, Team and Enterprise (Team/Enterprise owners must enable it), but not with API keys or setup-token tokens. Already in an interactive session? Type /remote-control. Note that while connected, the transcript is stored on Anthropic's servers.

Option 2: Telegram or Discord via Channels (research preview)

Channels push chat messages into a running session. They require Bun and a bot token from BotFather. As the claude user:

curl -fsSL https://bun.sh/install | bash
source ~/.bashrc                # the installer adds ~/.bun/bin to PATH here
claude
# at the Claude Code prompt:
/plugin install telegram@claude-plugins-official
/telegram:configure <token>
# exit, then restart (inside tmux) with the channel enabled:
claude --channels plugin:telegram@claude-plugins-official
# message your bot, then at the prompt:
/telegram:access pair <code>
/telegram:access policy allowlist

Know the trade-offs: messages only arrive while the session is open, a permission prompt pauses the session until someone answers it, and the flag syntax may change during the preview. We compare it in depth in MyCloudAlly vs Claude Code Channels.

Option 3: Plain SSH from your phone

Any mobile SSH client plus tmux attach works and needs nothing extra. It's just cramped on a small screen.

How do I schedule Claude Code jobs with cron?

Use non-interactive mode, claude -p. In recent versions, -p runs start in Manual mode and deny anything that needs approval, so set an explicit permission mode. acceptEdits lets it write files in the working directory, and --permission-prompts none tells it nobody is around to answer. Create ~/bin/daily-report.sh as the claude user:

#!/usr/bin/env bash
set -euo pipefail
cd /home/claude/projects/myapp
/home/claude/.local/bin/claude -p "Summarize errors from the last 24 hours in logs/ and write the summary to reports/latest.md" \
  --permission-mode acceptEdits --permission-prompts none

Then make it executable and schedule it with chmod +x ~/bin/daily-report.sh and crontab -e:

0 7 * * * /home/claude/bin/daily-report.sh >> /home/claude/cron.log 2>&1

Cron runs as the same user, so it uses your stored login. If you'd rather it not depend on that login, create a token with claude setup-token, save export CLAUDE_CODE_OAUTH_TOKEN=... in a chmod 600 file, and source it inside this script only.

How do I secure a server where an AI agent has shell access?

Assume the agent will eventually run a command you didn't expect, and limit what that can cost you:

{
  "permissions": {
    "deny": ["Read(./.env)", "Read(./.env.*)", "Read(./secrets/**)"]
  }
}

What does running Claude Code 24/7 cost?

ItemTypical monthly cost
4 GB VPS~$5–$24 depending on provider
Snapshots/backupsUsually a small add-on
Claude plan (pricing)Pro $20 ($17/mo billed annually), Max $100, Ultra $200
Your time~1 hour to set up, plus re-logins, updates and fixes

Rather not run a server at all?

Honestly: if you're comfortable maintaining a Linux server, the DIY route above is cheap, and you'll learn a lot. If what you actually want is the result (apps built and live on your own domain, with nothing to maintain), MyCloudAlly is a different kind of product: an AI developer for people who don't code, that you simply text. See how it works.

Plenty of our customers aren't developers at all. See how a Mesa, AZ family runs their SEO with an AI assistant and how Rick Ayres made $3,000 from one app, or read more reviews.

Month-to-month · cancel anytime · plus your own Claude plan.

FAQ

How much RAM does Claude Code need on a VPS?

Anthropic lists 4 GB+ RAM and an x64 or ARM64 CPU. Add 2 GB of swap, and go bigger if the agent will also run databases or heavy builds.

Can I use my Claude Pro or Max subscription on a server?

Yes. Run claude auth login, open the printed URL elsewhere, and paste the code back. For scripts, claude setup-token prints a one-year token for CLAUDE_CODE_OAUTH_TOKEN, but it can't start Remote Control.

Does Claude Code keep running after I close SSH?

Not by default. Start it in tmux or screen, and use a systemd service for reboots and crashes.

How do I control it from my phone?

Use Remote Control with the Claude app or claude.ai/code. It needs only outbound HTTPS. Or use the Channels research preview for Telegram and Discord, which requires Bun and an open session.

Is it safe to give Claude Code shell access on a server?

It can be, with a non-root user without sudo, no production secrets, deny rules, a private Git remote, and snapshots. Avoid --dangerously-skip-permissions outside isolated environments.