SSD Nodes Learn Hosting plans →
How to do am Matt ConnorBy Matt Connor

How to Host Ollama for VPS LLM Without Exposing Am

A 7B model fit need 8 GB RAM and run 4 to 10 tokens per second on CPU. Use 127.0.0.1:11434/v1 and keep port 11434 closed.

Wetin you dey build

Na one open-weight language model wey dey run for server wey you own. E go answer requests through an HTTP API. If you want, e fit also get chat page wey you go open for browser. Ollama na the part wey downloads the model, loads am into memory, and serves requests on http://127.0.0.1:11434. Installation na one command. The hard parts dey elsewhere: choosing model wey your VPS fit actually hold for RAM, and making sure you no accidentally publish inference server wey no get authentication to the whole internet.

Make we start with two honest warnings. CPU-only VPS dey run small models slowly. The API no get built-in authentication at all. We go explain both well below, because na these two areas dey cause serious problems.

Numbers wey go show the real sizing

Model memory footprint roughly na the model file size, plus about 1 gigabyte runtime overhead, plus extra space for context window. Default tags for plenty popular Ollama models, including llama3.2:3b, llama3.1:8b and mistral:7b, na 4-bit quantized (dem label am Q4_K_M). E dey use about half gigabyte RAM for every 1 billion parameters. No be every default tag be Q4: small models like smollm2:135m dey ship with 16-bit, so check the quantization line for the model library page before you calculate. The arithmetic simple, and na e decide everything. The last part na the one wey you set yourself: if you raise num_ctx pass Ollama small default you get space for longer prompts, but the KV cache for RAM go grow. So choose context length before you decide whether the model fit.

A 3B model like llama3.2:3b na about 2 GB download, and e need around 4 GB free RAM to run. A 7B or 8B model like mistral:7b or llama3.1:8b na about 5 GB for disk, and e need about 8 GB RAM, or 16 GB to run comfortably. A 13B or 14B model need roughly 16 GB. Anything from 30B to 70B need server wey get plenty RAM or, realistically, GPU. For CPU VPS, e either no go fit, or e go answer so slowly say e no useful.

Now make we talk about speed, because na here people dey underestimate things. CPU inference depend on memory bandwidth, no be clock speed, and shared vCPU VPS get modest bandwidth. Expect single-digit to low-double-digit tokens per second: 7-8B Q4 model fit manage 4 to 10 tokens per second, while 3B model fit manage 10 to 25. GPU dey roughly one order of magnitude faster. These figures rough on purpose. The correct thing na to measure your own box, and the run step below show how to do am. Trust your eval rate, no be number wey you see for any article, including this one.

The practical conclusion be say small quantized models for CPU dey genuinely useful for drafting, summarizing, and classification if you fit accept the speed. For anything bigger or faster, budget for GPU instance. If you prefer make you see this arithmetic from start to finish for one specific model, running Nemotron 3.5 Lightning for VPS explain which tag to pull, the RAM wey e really need, and whether CPU-only fit keep up.

To compare one specific model with one specific box, estimate the model memory footprint here:

ToolLLM VRAM and model-size calculator

Install Ollama

Ways two dey wey clean. Official script na the easiest one for bare VPS:

curl -fsSL https://ollama.com/install.sh | sh

Dis one go create system user wey dem name ollama, install the binary for /usr/local/bin/ollama, and register systemd service wey dem call ollama.service. E go start when system boot and e go bind to 127.0.0.1:11434. Confirm say e dey up:

systemctl status ollama
ollama --version

If Docker dey already run for your side, use the container instead:

docker run -d --name ollama \
  -p 127.0.0.1:11434:11434 \
  -v ollama:/root/.ollama \
  --restart always \
  ollama/ollama

Pay attention to the 127.0.0.1: prefix for the port mapping. E dey bind the port to localhost only. If you write -p 11434:11434 instead, e go publish the port for every interface. Na the mistake wey the security section dey warn about. Choose one install method. No run the script and the container at the same time, because two processes go dey fight over the port.

Pull and run your first model

ollama pull llama3.2:3b
ollama run llama3.2:3b

pull go download the model layers enter disk (about 2 GB for this one). run load dem enter memory and put you for one >>> prompt. Type one question. The first token fit take several seconds while the weights dey load from disk enter RAM, then the answer go stream. Type /bye to comot from the chat; Ollama go continue dey run for background.

See wetin dey loaded and how e fit the system:

ollama ps

The PROCESSOR column na the real truth. 100% CPU mean say GPU no dey involved, and na there the slowness come from. Measure the real speed with the verbose flag:

ollama run --verbose llama3.2:3b "Write two sentences about Linux."

The eval rate line wey print for the end na your tokens per second for this hardware. Na this number you need plan around.

Models dey live for where, and how much disk you suppose buy

The script install dem and the service run dem from ollama user's home:

sudo du -sh /usr/share/ollama/.ollama/models

If you run am interactively as your own user, dem dey for ~/.ollama/models. For the container, dem dey inside the ollama named volume. This matter because quantized weights dey add up quickly: 3B na ~2 GB, 7-8B na ~5 GB, and 14B na ~9 GB. If you pull four models to compare dem, you don use 20 GB before you notice. Size the disk based on the models wey you plan to keep, and delete the rest with ollama rm <model>. If the same VPS already dey run something wey get big storage appetite, like PhotoPrism or Immich wey dey hold photo library, subtract that space from the free space first. Treat wetin remain as your real model budget.

Run am as service wey you dey control

The install script don already register ollama.service, so e go restart when system boot without any extra work. The setting wey worth changing na how long model go remain resident, and, for some setups, the bind address. Put both inside systemd drop-in so Ollama upgrade no go overwrite dem:

sudo systemctl edit ollama.service

Add this under the [Service] header wey the editor show you:

[Service]
Environment="OLLAMA_KEEP_ALIVE=30m"

OLLAMA_KEEP_ALIVE na how long model go stay for memory after the last request (default 5 minutes). Increase am for box wey you dey query throughout the day, so e no go reload the weights every time. Set am to 0 for box wey RAM tight, so e go free RAM immediately request finish. If you want model to remain resident forever instead of for fixed period, keep Ollama model loaded permanently explain the per-request keep_alive field and how to warm the weights again after reboot instead of waiting for the first slow request. systemctl edit reloads the unit files for you, so restart to apply the change:

sudo systemctl restart ollama

Di security point wey matter pass

By default, Ollama dey bind to 127.0.0.1:11434, so na only processes for the VPS itself fit reach am. That default correct. Keep am.

The API no get authentication. None. E no get API key, login, or rate limit. OLLAMA_ORIGINS only control which browser origins fit call am (CORS); e no stop curl or script wey dey another machine. Anybody wey fit reach port 11434 fit run any model wey you don pull, pull new ones, delete dem, and pin your CPU or GPU for full load indefinitely.

So na this one mistake you no suppose ever make: no set OLLAMA_HOST=0.0.0.0 and open 11434 for your firewall. That one go publish unauthenticated inference server to the whole internet. No configuration fit make raw 11434-on-0.0.0.0 safe, because none of Ollama documented settings add authentication to the local API, and origin allow-list no be login. Na rule for this particular service, no be ban say you must never open port: self-hosted RustDesk relay for remote desktop must accept public traffic before e fit do its work, and e get that permission because e carry its own key-based authentication and short, documented list of ports. Ollama no get any of those.

Three safe ways dey to reach the model from somewhere wey no be the box:

  • Keep am local. If na only another program for the same VPS, cron script, bot, or MCP server wey dey connect your tools to the model go call am, leave the bind for 127.0.0.1 and make that program call http://127.0.0.1:11434. Nothing dey exposed, and you no need anything else.
  • Reach am through private tunnel. Put the VPS for WireGuard VPN wey you host yourself, set OLLAMA_HOST to the tunnel address (for example 10.8.0.1, no be 0.0.0.0), and na only VPN peers fit connect. Public internet still no go see anything for 11434.
  • Put authenticating reverse proxy for front. Terminate TLS and require password or token for nginx, Traefik, or Caddy, then proxy go 127.0.0.1:11434. Ollama go keep its localhost bind; na only the proxy go listen on the public port. Na the same arrangement as putting Let's Encrypt certificate for nginx in front of any local service.

The reverse-proxy option na exactly wetin the chat UI go give you next, with real login attached.

Add chat UI with Open WebUI, wey dey behind TLS

Open WebUI na self-hosted chat interface. Run am for Docker and point am to the local Ollama:

docker run -d \
  --name open-webui \
  --network=host \
  -e OLLAMA_BASE_URL=http://127.0.0.1:11434 \
  -v open-webui:/app/backend/data \
  --restart always \
  ghcr.io/open-webui/open-webui:main

The --network=host flag na the important detail for Linux VPS. E put the container for the host network namespace, so 127.0.0.1 inside the container na the host own loopback, and the container fit reach Ollama for 127.0.0.1:11434 without Ollama listening for any other interface. The bridge-network recipe wey you go see elsewhere, --add-host=host.docker.internal:host-gateway with OLLAMA_BASE_URL=http://host.docker.internal:11434, no work here: that name resolve to Docker bridge gateway, and service wey bind to 127.0.0.1 for the host no dey reachable across the bridge. So Open WebUI just dey report say e no fit connect to Ollama.

The trade-off of host networking be say Open WebUI now dey listen for host port 8080 on every interface; any -p mapping go discard, and Docker go print warning to explain am. So close 8080 for both the host firewall and provider firewall, then make TLS reverse proxy be the only public entry point. On the first visit, Open WebUI go ask you to create admin account. That account na your authentication layer, so choose strong password.

To open the chat from your laptop over HTTPS, put TLS reverse proxy in front of 127.0.0.1:8080. If you already dey route several Docker apps for the server, Traefik with automatic TLS across many apps na the cleanest fit: one label block go issue the certificate and route chat.example.com to Open WebUI. That same label-per-app routing na wetin every other browser front-end for the server go use, whether na status dashboard or something more playful like Halcyon, wey dey present Jellyfin library as 90s rental store, each one for its own hostname behind its own login. The rule from the security section still apply: the proxy dey control the public port and login, while Ollama remain for localhost and Open WebUI own 8080 remain firewalled.

Use the OpenAI-compatible endpoint from your code

Ollama dey support small part of OpenAI chat API for /v1, so most OpenAI client libraries go work after you change two things: the base URL and one temporary key.

from openai import OpenAI

client = OpenAI(base_url="http://127.0.0.1:11434/v1", api_key="ollama")

resp = client.chat.completions.create(
    model="llama3.2:3b",
    messages=[{"role": "user", "content": "Name three Linux distributions."}],
)
print(resp.choices[0].message.content)

Client library dey require api_key, but Ollama no dey use am, so any string go work. For local inference, model must be the name of model wey dey available for the server. The model fit don pull before, create with ollama create, or copy with ollama cp. If the name no dey exist, e go return 404 with model 'x' not found. Plain curl call na the same idea:

curl http://127.0.0.1:11434/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{"model":"llama3.2:3b","messages":[{"role":"user","content":"Hello"}]}'

Na so you fit connect the model to agent and editor tooling too. If you already dey develop for the server, local model fit support scripts and plugins together with Claude Code wey dey run for the VPS inside tmux. This one keep cheap, private drafting work away from paid API, while hosted model handle the heavy reasoning.

Wahala wey fit happen, with the exact strings wey you go see

The process na "Killed" for middle of generation. You start large model and terminal print Killed, or server log (journalctl -u ollama) show line wey start with llama-server process has terminated. Na so Ollama 0.40.7 write am, checked 21 October 2026; older releases talk say llama runner process has terminated: signal: killed. Linux OOM killer stop am because the model need more RAM pass wetin the box get. Confirm the cause with sudo dmesg | grep -i oom, where you go see line like Out of memory: Killed process .... The fix na smaller model or model wey get heavier quantization, llama3.2:3b instead of 13B, or add swap so load wey pass physical RAM small fit survive slowly instead of dying. Swap dey change instant crash to slow answer; e no make 70B model practical for 4 GB. The kill dey happen silently unless you dey watch terminal, so for box wey you dey query from another place, attach OnFailure= unit to ollama.service wey go post to ntfy server wey you host for push alerts. This go tell you immediately when e die instead of making you discover am for the next request.

Ollama refuse to load the model. The request fail immediately with error instead of crashing, and server log record model is too large for system memory (Ollama 0.40.7, checked 21 October 2026). Older releases print Error: model requires more system memory (X GiB) than is available (Y GiB) directly for prompt. This na the polite version of the crash above: Ollama calculate the memory and stop instead of allowing OOM killer do am. Choose model wey requirement dey below your free RAM (check with free -h), reduce context length, or move to larger VPS. No flag fit make model enter; the memory na real.

The first token take forever, then everything dey okay. Cold model no print anything for five to thirty seconds, then e stream normally. That pause na the weights dey load from disk into RAM for the first time, and slow storage make am worse. Once e load, the model stay resident for the length of OLLAMA_KEEP_ALIVE, so the second prompt answer immediately. If that first load pass a timeout somewhere for the call path, you go get error instead of slow answer, and working out which layer report context deadline exceeded go show whether na client, proxy, or the load itself run out of patience. Increase that value if the gaps dey disturb you, and use ollama ps to see whether model dey loaded currently.

Everything just dey slow. Ten tokens per second or less, with no error at all. Na CPU inference dey do exactly wetin CPU inference dey do. ollama ps show 100% CPU, meaning say no GPU dey available. This no be bug, and no setting fit turn CPU to GPU, because memory bandwidth na the main limit. But one setting worth testing on VM: Ollama allow llama-server auto-detect thread count unless you set num_thread yourself. For an ollama run --verbose session, try /set parameter num_thread 4 (or your vCPU count), run the same prompt again, and keep the value wey give the best eval rate. After that, use smaller model, accept the speed, or move to GPU instance. Measure your real rate with --verbose before you decide say anything spoil. When the wait come from answer length instead of rate, capping the reply with num_predict go stop model wey like to talk too much from spending minutes on tokens wey you no go read.

Connection refused from another machine. From your laptop, current curl (8.23.0, checked 21 October 2026) print curl: (7) Failed to connect to <ip>:11434 after <n> ms: Could not connect to server, and the curl 8.5.0 wey Ubuntu 24.04 ship print curl: (7) Failed to connect to <ip> port 11434 after <n> ms: Couldn't connect to server. The words "Connection refused" only show if you add -v, for line wey read connect to <ip> port 11434 from ... failed: Connection refused. This na how e suppose work: Ollama bind localhost only. No try "fix" am by binding 0.0.0.0, because na exactly the exposure mistake wey we talk about above. Reach the model through VPN or through authenticating proxy instead.

You expose 11434 to the internet. If you set OLLAMA_HOST=0.0.0.0, open firewall, and now dey see model pulls wey you no start or CPU pinned at 100% by unknown clients, dem don find you and use the service. This na the main mistake, no be unusual case. Bind am again to 127.0.0.1 or the VPN address, close 11434 for firewall, and put authentication in front. Assume say strangers query anything wey dey reachable for that address during the time wey e open.

Backups and upgrades

State wey fit loss no plenty. You fit download the models again, so na only Open WebUI data volume, accounts, chat history, settings, and any systemd drop-in wey you write worth backing up. Back up the volume with a temporary container:

docker run --rm -v open-webui:/data -v "$PWD":/backup alpine \
  tar czf /backup/open-webui.tgz -C /data .

Upgrade Ollama by running the install script again; upgrade Open WebUI with docker pull ghcr.io/open-webui/open-webui:main, then recreate the container. One disk matter for the 0.40 line: Ollama 0.40.2 start to upgrade models wey earlier versions pull for background, and e keep the original copies as backups. Because of this, dem go use extra disk space until you remove dem. Ollama 0.40.3 (11 October 2026) pause that background upgrade. Check df -h after upgrade, and read the release notes for the command wey delete those backups. No pin anything for long term: model quality and runtime dey change fast, so read the release notes and run benchmark again for your own machine instead make you trust last quarter numbers.

FAQ

I fit really run LLM for CPU-only VPS?

Yes, but e get limit. Small quantized models for 3B to 8B range fit run for CPU and dem useful for drafting, summarizing, and classification, but dem go slow, around single-digit to low-double-digit tokens per second for shared vCPU. Anything from 13B upward go run painfully slow, or e no go fit enter RAM at all. If you need real speed or larger models, you need GPU instance.

How much RAM each model need?

For 4-bit (Q4) tags wey most popular models use by default, rough rule na about 0.5 GB RAM for every billion parameters for the weights, plus roughly 1 GB overhead and small extra space for context. So, 3B model need about 4 GB free, 7-8B model need about 8 GB, and 14B model need about 16 GB. Check your available headroom with free -h, and leave space for the operating system and other things wey dey for the box.

Ollama API get authentication?

No. Ollama no get built-in authentication, API key, or rate limit. Anybody wey fit reach port 11434 get full control of am. Its OLLAMA_ORIGINS setting only limit which browser origins fit call am; e no control who fit connect. Na exactly why e dey bind to 127.0.0.1 by default, and why you must never expose 11434 on 0.0.0.0 to the internet. Reach am locally, through private VPN, or through reverse proxy wey add login.

How I fit add web chat interface?

Run Open WebUI for Docker with --network=host so e share the host loopback and reach native Ollama for http://127.0.0.1:11434. Then put TLS reverse proxy in front of its port 8080 so you fit access am from your laptop. Keep 8080 closed for the firewall, so the proxy go be the only public door. Open WebUI own admin account provide the login, and you go set the password when e launch for the first time.

How I fit call am from my own application?

Use the OpenAI-compatible endpoint for http://127.0.0.1:11434/v1. Point any OpenAI SDK to that base URL, pass any string as the API key because Ollama go ignore am, and set model to a name wey dey available for the server through ollama pull, ollama create, or ollama cp. Existing OpenAI code usually go run without changes, apart from the base URL and key.

Dis article help you?