Run Agents on a Cloud Server

Run Claude Code or Codex on a cloud server: install the tools, set the key and endpoint, keep tasks alive with tmux, and switch to key-based SSH safely.

Updated 2026-11-26

Need an API key? Sign up →Endpoints & base URLs →

On This Page

Last verified: 2026-10-20 · 📄 Per qcode.cc and official docs (tmux / OpenSSH / Ubuntu Server)

ℹ️ The configuration page and the console for cloud servers currently come only in Chinese and English. Product page: https://qcode.cc/en/cloud

🚀 No server yet? Pick a line and order at qcode.cc/en/cloud — a 1-day trial is available, billed in 1 / 3 / 6 / 12-month terms.

Running Claude Code or Codex on a machine that stays on: a job that takes half an hour or several hours must not die when the SSH connection drops, and you have to be able to come back and look at it. That is what a cloud server is for. Install the tools, set the key, and then two things matter: letting the task survive a dropped SSH session, and moving to key-based login.

For how to buy the machine see Cloud Servers: Picking, Buying and Using; for billing and refunds see Cloud Server Billing and Rules.

Install Claude Code / Codex on the server

The cloud server page gives exactly these two commands; run them on the server:

curl -fsSL https://qcode.cc/install/claude-code.sh | bash -s -- --lang en
curl -fsSL https://qcode.cc/install/codex.sh | bash -s -- --lang en

The script's messages are in English (--lang accepts only zh and en).

The script benchmarks the access domains, asks for your cr_ key, writes the configuration, installs Node.js and the CLI if needed, and finishes by sending a minimal request to verify connectivity. All the flags and the rollback steps are in the One-Click Setup Script.

Set the QCode key and the endpoint

The one-click script already wrote the configuration for you. If you want to write it by hand — or just want to check what it wrote — these are the two places to look, matching what Environment Variables and Codex Quick Start describe:

Claude Code (Anthropic protocol):

export ANTHROPIC_BASE_URL="https://api.qcode.cc/api"
export ANTHROPIC_AUTH_TOKEN="cr_your_key"

Codex (OpenAI Responses protocol) — create the directory first, then write ~/.codex/config.toml:

mkdir -p ~/.codex
model_provider = "qcode"
model = "gpt-6.2-sol"
model_reasoning_effort = "high"

[model_providers.qcode]
name = "qcode"
base_url = "https://api.qcode.cc/openai"
wire_api = "responses"
requires_openai_auth = true

~/.codex/auth.json:

{
  "OPENAI_API_KEY": "cr_your_key"
}

auth.json holds the key in plaintext, so tighten its permissions right away so other users on the same machine cannot read it:

chmod 600 ~/.codex/auth.json

Afterwards check that base_url is https://api.qcode.cc/openai, that ANTHROPIC_BASE_URL is https://api.qcode.cc/api, and that the key starts with cr_. A hand-written export only affects the current shell; to have a tmux session that is already running pick it up, run it inside the tmux session or put it in ~/.bashrc.

Keep tasks running after SSH drops with tmux

If you run the job over a plain ssh root@<IP>, the foreground process dies with the connection. tmux sessions are persistent — the manual says:

Each session is persistent and will survive accidental disconnection (such as ssh(1) connection timeout) or intentional detaching (with the ‘C-b d’ key strokes).

In other words: the session stays whether SSH drops unexpectedly or you detach yourself with C-b d.

Three commands you will use all the time (if tmux is not installed yet, install it with your system's package manager first; on Ubuntu that is sudo apt install tmux):

tmux new -s agent      # create a session named agent and enter it
tmux ls                # list every session on the server
tmux attach -t agent   # attach to that session again

To step away, press Ctrl-b and then d to detach — the manual's default bindings use the C-b prefix, and d stands for "Detach the current client." (detach the current client). The job keeps running in the session; when you come back, tmux attach puts you back in. The manual's own way to reattach is $ tmux attach.

SSH security: switch to key login, verify it works, then turn off passwords

When ordering, you can also add an SSH public key directly and optionally choose "Key login only (turn off root password login)". The steps below are the manual way to switch to key login.

The order matters. The Ubuntu documentation warns about exactly this when it comes to changing the OpenSSH configuration: if SSH is your only way in and you get the configuration wrong, a restart can lock you out of your own server. So verify first, disable afterwards.

The commands below use Ubuntu as the example. Other distributions use different service names and configuration paths — check that system's own documentation; the order (verify the key, then disable passwords, check before restarting) stays the same.

🔐 The key-login steps below use root to keep the order easy to follow. For long-term use, do not keep running agents as root: create a regular user as described in the last subsection, confirm it can log in and use sudo, then set PermitRootLogin to no and open only the necessary ports in your security group / firewall.

  1. Generate the key pair on your own machine:
ssh-keygen -t ed25519
  1. Put the public key on the server (run this on macOS / Linux, or in WSL on Windows; the chmod command runs on the server, in your home directory after you log in):
ssh-copy-id root@<IP>

The Ubuntu page says to append the content of id_ed25519.pub to ~/.ssh/authorized_keys on the target machine, and to double-check the permissions of that file — only the authenticated user may have write permission; if they are not right, run chmod go-w .ssh/authorized_keys.

  1. Verify that the key gets you in. The point is that you can log in without being asked for a password. This step must not be allowed to fall back to a password, otherwise a key that was not installed correctly still gets in:
ssh -o PasswordAuthentication=no -o PreferredAuthentications=publickey -i ~/.ssh/id_ed25519 root@<IP>

With -o PasswordAuthentication=no a wrong key fails straight away with Permission denied instead of prompting for a password; if you are refused, do not carry on — go back to step 2. At this point do not close the session you are still logged into with a password; open a second terminal window.

  1. Only after that works, turn password login off. First find out which files control the option — on Ubuntu /etc/ssh/sshd_config starts with Include /etc/ssh/sshd_config.d/*.conf, and settings in sshd_config.d/ override the main file:
sudo grep -rEi '^\s*PasswordAuthentication' /etc/ssh/sshd_config /etc/ssh/sshd_config.d/

Change every line that matches to PasswordAuthentication no (including a yes in a file under sshd_config.d/). Only if nothing matched at all do you add the line PasswordAuthentication no to the end of /etc/ssh/sshd_config. The reason: OpenSSH uses the first value it reads for each keyword, and files pulled in by Include are expanded in lexical order first, so editing only the main file often has no effect. Leave PubkeyAuthentication at yes.

  1. Check the syntax, look at the effective values, then restart:
sudo sshd -t
sudo sshd -T | grep -Ei '^(passwordauthentication|pubkeyauthentication) '

sshd -T prints the configuration sshd will actually use (sshd(8)'s "extended test mode": the configuration is written to standard output). Continue to the restart only if you see passwordauthentication no and pubkeyauthentication yes; if passwordauthentication is still yes, another file is overriding it — go back to the previous step. If sshd -t reports an error, do not restart yet.

sudo systemctl restart ssh.service
  1. Check again after the restart, and keep the old session open. Open a new terminal and log in with the key once more, using the same command as in step 3; then try a password-only login, which should be refused:
ssh -o PubkeyAuthentication=no root@<IP>

Seeing Permission denied means password login is off; only when both checks behave as expected do you close the original session.

Finishing up: a regular user, no direct root login, only the ports you need

Do not run agents as root long-term. Once key login is confirmed working, finish with these four steps:

  1. Create a regular user and grant sudo (on the server):
sudo adduser deploy
sudo usermod -aG sudo deploy
  1. Install your public key for the new user too (on your own machine) and verify both key login and sudo:
ssh-copy-id deploy@<IP>
ssh -o PasswordAuthentication=no -i ~/.ssh/id_ed25519 deploy@<IP>

After logging in, run sudo -v; continue only if it succeeds.

  1. Turn off direct root login, then check and restart sshd:
echo 'PermitRootLogin no' | sudo tee /etc/ssh/sshd_config.d/99-hardening.conf
sudo sshd -t
sudo sshd -T | grep -i '^permitrootlogin '
sudo systemctl restart ssh.service

Restart only after you see permitrootlogin no; keep this file to that single line so it does not override the PasswordAuthentication settings from the previous step.

  1. Limit the exposed ports: in the cloud console's security group, allow only 22 (add 80 / 443 if you serve the web), and restrict the source to your own egress IP where possible rather than opening 0.0.0.0/0. Then enable ufw on the server:
sudo ufw allow OpenSSH
sudo ufw enable
sudo ufw status

Always allow OpenSSH before enable, or you may lock yourself out.

💡 At this point you have a machine that can run agents for the long haul: the tools are installed, the key and endpoint are set, tasks survive a dropped connection, and you log in with a key.

What it costs: two parts

  • The server: charged from your balance for the term you pick at order time (1, 3, 6 or 12 months) — longer terms cost less per month. The starting price is in the “Compare lines” table on qcode.cc/en/cloud.
  • The models: billed per token, with per-model rates listed on qcode.cc/models.

Both come out of the same account balance.

👉 Ready to order, or want to compare lines and prices first: qcode.cc/en/cloud

Get started with QCode

One API key for Claude Code, Codex and more — billed per token, per-model prices on qcode.cc/models

Enterprise →