Skip to contentcloudvix
cloudvix
GuideDevelopers & AI

Run a language model with Ollama on a VPS, without opening a port

Denys DunaievskyiFounder, Cloudvix
  • 11 min read
  • Published
  • LevelIntermediate
Guides
On this page

Key takeaways

  • Ollama has no login: anyone who can reach the port can use your server’s processor and list and delete your models.
  • A model has to fit in memory with room to spare for the system, and its file also has to fit on the disk.
  • Running a model on the processor is slow by nature, and a larger model is slower.

Ollama downloads language models and runs them on your own machine, with a small web API on top. On a server it means your prompts and answers stay on a machine you control and you pay for the server, not for each request. This guide installs Ollama on Ubuntu 24.04, runs one small model on the processor, reaches it from your computer through an SSH tunnel and keeps the port closed to everyone else.

Before you start

You need an Ubuntu 24.04 server and a user with sudo, as in the first-hour guide. This guide runs the model on the processor, as on a server without a graphics card. The model used here is llama3.2:1b, a small one chosen so the first run is quick; the download is in the order of a gigabyte, and the first step shows whether your server has the room.

  • an Ubuntu 24.04 server and a user with sudo
  • memory for the model file plus a few GB for the system, and free disk space for the model files (the first step shows both)
  • a computer with an SSH client for the tunnel step

The steps

See what the server can hold

nproc gives the number of processor cores, free -h the memory (look at available) and df -h / the free disk space. A model has to fit in memory with room to spare for the system, and its file also has to fit on the disk. Compare these numbers with the size that ollama pull prints in a later step. Plan for a few GB of disk for the installer and Ollama itself, on top of the model file.

On the serverbash
nproc
free -h
df -h /

Install Ollama

Ollama publishes an install script. Instead of piping it straight into a shell, this downloads it, lets you read it with less (press q to leave) and runs it afterwards. The script creates a system user and a service named ollama and needs sudo. Without a graphics card it prints a warning that no GPU was detected; that is normal here, the model runs on the processor.

On the serverbash
curl -fsSL https://ollama.com/install.sh -o ollama-install.sh
less ollama-install.sh
sh ollama-install.sh

Check the service and who can reach it

The version must print, the service must be active, and the last command must show that Ollama listens on 127.0.0.1:11434, the server itself only. If it shows 0.0.0.0 or *, the port is open to the network.

On the serverbash
ollama --version
systemctl is-active ollama
sudo ss -ltnp | grep 11434
Warning

Do not set OLLAMA_HOST to 0.0.0.0 and do not open port 11434 in the firewall. Ollama has no login: anyone who can reach the port can use your server’s processor and list and delete your models.

Download a model and talk to it

ollama pull downloads the model and prints its size. ollama list shows what is installed. ollama run sends one question and prints the answer; run it without the quoted text to open an interactive chat and leave it with /bye.

On the serverbash
ollama pull llama3.2:1b
ollama list
ollama run llama3.2:1b "Say hello in one short sentence."

Call the API from the server

Ollama’s API listens on port 11434. This sends one request and waits for the whole answer ("stream": false), which comes back as JSON with the text in the field response.

On the serverbash
curl -s http://127.0.0.1:11434/api/generate -d '{"model": "llama3.2:1b", "prompt": "Say hello in one short sentence.", "stream": false}'

Reach it from your computer through an SSH tunnel

Run the first command on your computer and leave it open: it forwards port 11434 of your computer to the server’s port 11434 through the SSH connection, and -N runs no command. In a second window, the second command now talks to the server’s Ollama and must list the model. If port 11434 is already taken on your computer, for example by a local Ollama, use 11435:127.0.0.1:11434 in the command and http://127.0.0.1:11435 in the check.

On your computerbash
ssh -N -L 11434:127.0.0.1:11434 ops@SERVER_IP
On your computerbash
curl -s http://127.0.0.1:11434/api/tags
Tip

An app on your computer can now use http://127.0.0.1:11434 as if Ollama ran locally. For an app on another server, a private tunnel such as WireGuard is the tidier way than an open port.

Watch memory while it answers

ollama ps lists the models loaded in memory and how much they take. By default Ollama unloads a model after about five minutes without a request. free -h and top show the effect on the whole server: if available falls close to zero or the server starts swapping, the model is too big for it.

On the serverbash
ollama ps
free -h
top -b -n 1 | head -n 12

Remove a model

Models take disk space until you remove them. The second command shows what was freed.

On the serverbash
ollama rm llama3.2:1b
df -h /

If something goes wrong

ollama pull stops with a disk error

The disk is full. Check df -h /, remove what you do not need (ollama rm for models you pulled, or the folders from the disk step in the swap guide) and pull again.

The answer never comes, or the process is killed

The model is too big for the memory. Look at sudo journalctl _TRANSPORT=kernel --since "1 hour ago" | grep -i -E 'out of memory|oom-kill|killed process'. Use a smaller model, add swap as a safety net or choose a server with more memory.

curl: (7) Failed to connect to 127.0.0.1 port 11434

The service is not running. Run systemctl status ollama --no-pager and sudo journalctl -u ollama -n 30 --no-pager and read the first error. On your computer, the same message means the tunnel is not open: start the ssh -N -L command again.

The answers are very slow

Running a model on the processor is slow by nature, and a larger model is slower. Try a smaller model, shorter questions and a server with more processor cores.

Questions people ask

Which plan do I need?

It depends on the model. The memory of the server must hold the model file with a few gigabytes to spare for the system. Start with a small model, watch ollama ps and free -h, and choose a bigger plan only if the numbers ask for it.

Do my prompts leave the server?

With a local model like the one in this guide, the questions you send and the answers you get are handled by the Ollama service on your server. The model files themselves are downloaded from Ollama’s library, and each model has its own licence, which you should read before you use it for a product. Ollama also offers models that run in its own cloud: do not choose those if the data must stay on your server. We have not audited what the software itself sends elsewhere; read its privacy statement if that matters to you.

Can I use it from an app on another server?

Yes, but keep the port closed to the internet. Use an SSH tunnel as in this guide, or a private network between the two servers such as the WireGuard setup in our guide. Do not open port 11434 and hope nobody finds it.

Where to go next

If you use Ollama from an app, give that app only the tunnel and nothing else on the server. The security checklist covers the rest of the server, and the guide on a read-only user shows how to give an assistant a way in that cannot change the system.

About the author

Denys Dunaievskyi

Founder, Cloudvix

Runs Cloudvix and is responsible for the guides published here.

Related guides

Your server is a few clicks away.

Choose the plan and the system in one order form; the location too, when there is more than one.

Create server