Run an AI Assistant on a Server with SSH and tmux

Connect to a server over SSH, run your assistant inside tmux so it keeps working after you disconnect, sign in without a browser, and stay safe.

Checked against official docs on 12 Oct 2026

On this page

A server is a computer that runs all the time in a data center. You rent it and control it from your own computer. When your assistant runs on a server, it can keep working on a long task while your laptop is closed.

You need three things:

  • A server with Linux, and its address, user name and password or key from your server company.
  • SSH, the standard tool to log in to another computer over the internet. Macs have it. Windows 10 and 11 have the OpenSSH client that Microsoft documents.
  • tmux, which keeps programs running after you disconnect. Read tmux in 5 commands if it is new to you.

Connect to the server

Open the terminal on your computer and type ssh, your user name, @ and the server address. For example:

ssh yourname@203.0.113.10

Replace yourname and 203.0.113.10 with your own details. The first time, SSH asks if you want to continue connecting. Type yes and press Enter. Then type the password. The password does not show while you type. That is normal.

When the prompt changes to the server name, every command you type runs on the server.

Use a normal user, never root

Many server companies give you a login as root, the administrator account. Never run an AI assistant as root: root can change or delete anything on the server, so one wrong command from the assistant could break the whole machine. A normal user can only change its own files.

If you logged in as root, make a normal user first. Ubuntu's documentation gives this command. Replace username with a name you choose, then follow the questions to set a password:

sudo adduser username

Then type exit to leave the server, and connect again as the new user:

ssh username@203.0.113.10

Do all the next steps as this user: tmux, the install, the sign-in and the assistant itself. Do not add this user to the sudo group, which gives full administrator rights, unless you really need it.

Start a tmux session

tmux new -s work

If the server says tmux is not found, install it first (see tmux in 5 commands).

Install the assistant on the server

Most servers run Linux. Use the Mac and Linux install line from your assistant's guide:

Then go to your project folder on the server with cd.

Sign in without a browser

A server has no browser, so sign-in works a little differently:

  • Claude Code: start claude. If no browser opens, press c to copy the sign-in link and open it on your own computer. If the browser then shows a code, paste it into the terminal at the Paste code here if prompted line.
  • Codex CLI: use device code sign-in. Turn on device code login in your ChatGPT security settings first, then run codex login --device-auth. Open the link on any device and type the code it shows.
  • Gemini CLI: Google's Sign in with Google needs a browser that can reach the computer where Gemini runs. On a server, a Gemini API key is the simpler way.

Google shows export GEMINI_API_KEY="YOUR_API_KEY" to set the key. That setting lasts only for the current terminal session. Also, a command that you type is saved in the shell's history file (for Bash, ~/.bash_history by default), so the key can stay there.

Google's documented alternative is a file: Gemini CLI reads its settings from ~/.gemini/.env by itself. Open that file in a text editor on the server and add one line with your key:

text
GEMINI_API_KEY="YOUR_API_KEY"

Keep this file in your home folder, not in your project folder. An API key bills per use or has its own daily limit, so read What AI assistants cost first.

Start the assistant and give it a task

Inside the tmux session, in your project folder, type the start command of your assistant:

AssistantStart command
Claude Codeclaude
Codex CLIcodex
Gemini CLIgemini

Then give it a clear, well-defined task. Write the task in plain words, with the result you expect.

Disconnect and come back later

Press Ctrl + B, then D, to detach. Now you can type exit to leave the server, or close the window. The assistant keeps working.

To come back, connect with ssh again, then type:

tmux attach -t work

You see the assistant exactly where it is. If it asked you a question while you were away, it waits for your answer.

Keep permissions safe

Every assistant can skip its safety questions. On a server it is tempting, because nobody watches. Be careful:

  • Claude Code: Anthropic says to use the mode that skips all permission prompts (bypassPermissions) only in isolated environments, such as containers or virtual machines, where Claude Code cannot cause damage.
  • Codex CLI: for unattended runs with codex exec (Codex without the chat screen), OpenAI suggests codex exec --sandbox workspace-write "<task>", so that Codex can edit only inside the project folder. Avoid --dangerously-bypass-approvals-and-sandbox unless you are inside a dedicated sandbox machine.
  • Gemini CLI: the yolo approval mode approves every action. Do not use it on a server with important data.

Also keep secrets, such as API keys and passwords, out of your project folder and your note files. Use a separate test project on the server until you trust your setup.

Sources