~/tools / Run a local LLM on your server / Ollama systemd Override Generator
Ollama systemd Override Generator — Build Ollama's systemd override: OLLAMA_HOST, OLLAMA_MODELS, KEEP_ALIVE and more
Build the systemd override that sets Ollama's environment variables on a Linux server: the listen address, the model directory, how long models stay in memory, the context length, parallel requests, Flash Attention, the K/V cache type, extra origins, local-only mode and an HTTPS proxy. Every variable comes from the official Ollama FAQ, and each value is quoted the way systemd reads it. Nothing leaves your browser.
Override for systemctl edit
Paste this into the editor that sudo systemctl edit ollama.service opens, between the two comment lines. It is saved as /etc/systemd/system/ollama.service.d/override.conf.
[Service] Environment="OLLAMA_KEEP_ALIVE=10m" Environment="OLLAMA_CONTEXT_LENGTH=8192" Environment="OLLAMA_MAX_LOADED_MODELS=1" Environment="OLLAMA_NO_CLOUD=1"
Commands
Run them on the server in this order. The last one shows the variables the service received. When you change OLLAMA_MODELS, the first two create the directory and give it to the ollama user; mkdir -p is our addition, because chown fails on a directory that does not exist.
sudo systemctl edit ollama.service sudo systemctl daemon-reload sudo systemctl restart ollama systemctl show ollama --property=Environment
Variables and defaults as given in the Ollama FAQ, and quoting rules from the systemd.exec manual, checked on 2026-11-03. Ollama FAQ / systemd.exec: Environment=
Everything is done in your browser. Nothing you enter is sent anywhere.
When Ollama runs as a systemd service on Linux, the official FAQ says to set its environment variables with systemctl edit ollama.service: add one Environment line per variable under [Service], save, then run systemctl daemon-reload and systemctl restart ollama. The steps are short, but the details are easy to get wrong. systemd expands specifiers, so a % sign has to be written as %%; a backslash or a double quote inside a quoted assignment is read as an escape; and a value with a space must be quoted as a whole. This tool writes the override for you. It offers only the variables documented in the FAQ, shows the documented default next to each one, quotes every assignment as "NAME=value" and doubles % signs. It warns when a value would make Ollama listen on every network interface, when a count is not a whole number, and when a quantized K/V cache is chosen with Flash Attention turned off. We tested the output on Ubuntu 24.04 with systemd 255: we pasted it into systemctl edit and confirmed that the service received each value unchanged, including spaces, $, ' and %.
The core logic of this tool is open source under the MIT License. github.com/seigo5555/toolkitbox-lib/src/ollama-systemd.ts
Use Cases
- Keep a model in memory longer, or unload it sooner, on a small VPS with OLLAMA_KEEP_ALIVE
- Move the model files to a larger disk with OLLAMA_MODELS
- Limit Ollama to one loaded model and set the default context length for a server with little memory
Usage
- Fill in only the variables you want to change. Empty fields are left out, so Ollama keeps its defaults. The grey text in each field is the default the FAQ gives.
- Read the warnings. A listen address other than 127.0.0.1 or localhost makes Ollama reachable from other machines, and the FAQ describes no authentication for it.
- Run sudo systemctl edit ollama.service, paste the text into the editor between the two comment lines, save and exit. Then run the remaining commands to reload systemd, restart Ollama and check the values it received.
FAQ
Where is the file saved?
systemctl edit saves it as a drop-in file, /etc/systemd/system/ollama.service.d/override.conf, and leaves the main unit file unchanged. When we ran it on Ubuntu 24.04, the editor showed the comment ### Anything between here and the comment below will become the contents of the drop-in file. Paste the text between that comment and the one below it.
Why is every value wrapped in double quotes?
The systemd documentation says that a value containing spaces or an equals sign must have quotes around the whole assignment. Quoting every line the same way keeps paths with spaces and lists such as OLLAMA_ORIGINS intact. The documentation also says that $ has no special meaning there, so it is passed as written, while % starts a specifier, so the tool writes %% for a literal %.
Which characters are not accepted?
Double quotes, backslashes and control characters such as tabs. Inside a quoted assignment systemd reads them as escapes or rejects them, so the value would not reach Ollama as typed. The tool reports them as errors and leaves that line out.
Is it safe to set OLLAMA_HOST to 0.0.0.0?
It makes Ollama listen on every network interface, so other machines can reach it. The FAQ says Ollama binds 127.0.0.1 port 11434 by default and describes no authentication for the server. Our recommendation, not a statement from the documents: keep the default and reach Ollama through an SSH tunnel or a proxy with a password and HTTPS, and limit port 11434 in the firewall.
Can I put a password in HTTPS_PROXY?
The tool warns when the proxy address contains a user name and password. The systemd documentation says that environment variables are not suitable for passing secrets, because the values set for a unit can be read by unprivileged clients. The FAQ also says to avoid setting HTTP_PROXY, because Ollama pulls models only over HTTPS and HTTP_PROXY may interrupt client connections, so the tool offers only HTTPS_PROXY.
Is anything sent to a server?
No. The override is put together in your browser.
Related articles
- Watch the memory of Ollama on a small VPSSee what Ollama holds in memory, how long it stays there and which settings change it: ollama ps, keep_alive and the limits, from the official FAQ.
- Connect Dify to Ollama on your own VPSRun Dify on your own VPS and use Ollama as its model: install, the plugin fields, the Docker address problem and embeddings, from the official documentation.
- Start a local LLM without an expensive PC: a beginner's guide to using a VPSNo powerful PC? Rent a VPS and run a small local LLM from your browser: six steps from memory estimate to a protected chat screen, with the limits stated honestly.