Ollama API No Get Password: How You Go Secure Am
Ollama API no require password. Anybody wey reach port 11434 fit run models, download new ones, or delete dem. See the three fixes, in order.
Ollama API no get password
Ollama API no get authentication. No user, no password, and no API key check dey for incoming clients. Anything wey fit open TCP connection to port 11434 fit list your models, run dem, download new ones, and delete the ones wey you get.
The official documentation talk am clearly: "The local API at http://localhost:11434 does not require authentication." The word local carry the whole security model. Ollama dey bind to 127.0.0.1 by default, so for laptop, loopback interface na the access control. If you move that listener go public address, the access control don disappear, because nothing replace am.
Na why this matter for VPS (virtual private server). The default setting safe. The first change wey most people make, na to open the listener so another machine fit use the model. Na that change remove all protection at once.
Wetin open port 11434 dey expose
Every endpoint. No read-only mode dey, and no separate admin port dey. Na these real requests be the ones, but dem dey target server address instead of localhost:
# List every model on the box
curl http://SERVER_IP:11434/api/tags
# See what is loaded into memory right now
curl http://SERVER_IP:11434/api/ps
# Run a prompt on your hardware
curl http://SERVER_IP:11434/api/generate -d '{"model":"llama3.2","prompt":"Why is the sky blue?"}'
# Write several gigabytes to your disk
curl http://SERVER_IP:11434/api/pull -d '{"model":"llama3.2"}'
# Remove a model
curl -X DELETE http://SERVER_IP:11434/api/delete -d '{"model":"llama3.2"}'For operator side, four things dey go wrong:
- Your CPU or GPU dey run inference for another person. For plan wey get fair-use CPU allowance, steady load mean stranger dey spend your allowance, and keeping AI workload costs under control on a VPS go hard more once you no be the only caller.
/api/pulldey write to your disk. Model sizes dey vary; evenllama3.2:1bna 1.3 GB. Pulls wey dey repeat fit fill the volume, and full disk fit break every other service for the box, no be only Ollama.- Requests dey enter your process and get logged. For default log level, Ollama dey record metadata only, so you get the endpoint, status, latency, and client address, but no prompt text. That still be record of who use your box and wetin dem use am do, dey sit inside your journal, and na you no choose to collect am.
/api/deletedey remove models. To get dem back mean say you go download dem again with your own bandwidth.
None of these things need exploit. Na the documented API dey behave exactly as dem design am.
Ed25519 key no be access control
Search for "Ollama API key" and you go see two different things. None of dem be password for your server, and separating dem go remove most of the confusion.
The first one na the identity key pair. Ollama dey generate Ed25519 key pair the first time e run. For Linux, the install script dey create system user named ollama, with home directory for /usr/share/ollama, so the pair dey here:
/usr/share/ollama/.ollama/id_ed25519
/usr/share/ollama/.ollama/id_ed25519.pubThat key dey point outside. ollama signin dey register the public half with your ollama.com account, and na am dey authorise you to push model to the registry or pull private one. E proves your machine to ollama.com. E no ask anything from clients wey dey connect to your machine. If you delete am, rotate am, or never create am, e no change who fit call your API.
The second one na OLLAMA_API_KEY. That variable dey hold key wey you create for https://ollama.com/settings/keys, and your client dey send am as Authorization: Bearer $OLLAMA_API_KEY when e dey call the hosted API for https://ollama.com/api. Na credential for their service, and na you dey use am as the client. Your own ollama serve no dey use am to authenticate incoming requests. If you set OLLAMA_API_KEY for your VPS, e no put password for your VPS.
So no setting dey wey you need switch on. The three defences below dey work the same way: make the port no reachable, then put something for front wey go check access.
Check wetin your server dey listen to right now
sudo ss -tlnp | grep 11434The safe result go name the loopback address:
LISTEN 0 4096 127.0.0.1:11434 0.0.0.0:* users:(("ollama",pid=812,fd=3))The exposed result go name every interface:
LISTEN 0 4096 0.0.0.0:11434 0.0.0.0:* users:(("ollama",pid=812,fd=3))0.0.0.0 mean all IPv4 addresses for the machine, including the public one. *:11434 and [::]:11434 na wildcard listeners for every IPv6 address. Whether dem also accept IPv4 depend on the socket IPV6_V6ONLY option, wey Linux leave off by default (net.ipv6.bindv6only=0), so treat any of the three as exposed.
Now confirm am from outside. Run this for your laptop, no be for the server:
curl -m 5 http://YOUR_SERVER_IP:11434/api/versioncurl: (28) Connection timed out after 5001 milliseconds na the answer wey you want, and curl: (7) Failed to connect ... Connection refused too. JSON object wey carry a version field mean say anybody wey ask fit reach the whole API. Testing with curl for the server itself no prove whether another machine fit reach am. If the server get IPv6 address, repeat the test against am with curl -6 -m 5 http://[YOUR_SERVER_IPV6]:11434/api/version, because closed IPv4 port no tell you anything about IPv6 listener.
Exposure normally happen for one of two ways. The first one na deliberate edit, because person need make another machine reach the model:
sudo systemctl edit ollama.service[Service]
Environment="OLLAMA_HOST=0.0.0.0:11434"That one line na the complete exposure. The second way na Docker, and e no require you to edit anything at all. That one get im own section below.
Defence 1: keep am for localhost and tunnel enter
Start with this one first. E no need new software, and e no create any credential wey fit leak. The port no dey exist for public interface, so scanning no fit find am.
Set the bind address directly instead of depending on the default:
sudo systemctl edit ollama.service[Service]
Environment="OLLAMA_HOST=127.0.0.1:11434"That one write /etc/systemd/system/ollama.service.d/override.conf. Apply am and check:
sudo systemctl daemon-reload
sudo systemctl restart ollama
sudo ss -tlnp | grep 11434ss suppose now show 127.0.0.1:11434. If e still show 0.0.0.0, another drop-in file dey take priority. Run systemctl cat ollama.service to list the unit and every drop-in with their paths, then delete the stale one.
To use the model from your laptop, forward the port through SSH:
ssh -N -L 11434:127.0.0.1:11434 you@your-server-L 11434:127.0.0.1:11434 open port 11434 for your laptop and send anything wey enter there go 127.0.0.1:11434 as the server dey see am. -N tell SSH make e no run remote command, so the process only keep the tunnel open. While e dey run, this one go work for your laptop:
curl -s http://localhost:11434/api/tagsYou go meet two failures. bind [127.0.0.1]:11434: Address already in use mean say that local address and port don already dey use, whether na Ollama, another SSH tunnel, or another program, so choose another local port with -L 11500:127.0.0.1:11434 and point your client to 11500. If request through the tunnel get empty reply, check ss for the server and SSH error output before you decide which service fail.
For several client machines, private network better pass one tunnel for each person. Put the machines on WireGuard or Tailscale, then bind Ollama to the address wey dey that network instead of 0.0.0.0:
[Service]
Environment="OLLAMA_HOST=10.8.0.1:11434"The port go then exist only for interface wey you need key to join. This one still work even if firewall mistake happen, because rule wey accidentally allow everybody still no fit expose listener wey public interface no hold.
Defence 2: reverse proxy wey dey check bearer token
When something for public internet must call the model, keep Ollama for loopback and put proxy for front of am. Proxy dey terminate TLS (transport layer security) and reject request wey no get correct header. Ollama still accept connection only from 127.0.0.1, so na proxy be the only way enter.
Generate real token first. No invent am by hand:
openssl rand -base64 36Nginx site wey dey check am:
map $http_authorization $ollama_ok {
default 0;
"Bearer PASTE_YOUR_GENERATED_TOKEN_HERE" 1;
}
server {
listen 443 ssl;
server_name llm.example.com;
ssl_certificate /etc/letsencrypt/live/llm.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/llm.example.com/privkey.pem;
location = /api/pull { return 403; }
location = /api/delete { return 403; }
location = /api/push { return 403; }
location / {
if ($ollama_ok = 0) { return 401; }
proxy_pass http://127.0.0.1:11434;
proxy_set_header Host 127.0.0.1:11434;
proxy_buffering off;
proxy_read_timeout 600s;
}
}Five lines dey do real work there, and each one dey prevent one failure wey you for otherwise encounter.
if inside location block normally no good idea for nginx, but body wey get exactly return na one of the two forms wey behave predictably, so this use safe.
location = /api/pull na exact match, and nginx rank exact matches above location / prefix, so e go refuse those three endpoints before e even check token. Valid token still grant access to other model-management endpoints, including /api/create and /api/blobs/:digest, so these three blocks no prevent every disk write.
proxy_set_header Host 127.0.0.1:11434; matter because Ollama dey inspect incoming Host and Origin headers. If you pass proxy public hostname straight through, e fit produce 403 Forbidden wey come from Ollama instead of nginx, and this fit make debugging confusing. OLLAMA_ORIGINS na the other control for browser client wey need specific origin allowed.
proxy_buffering off; matter because Ollama dey stream response token by token. When buffering dey on, nginx dey buffer response before e send am onward, and this delay delivery of streamed tokens.
proxy_read_timeout 600s; matter because nginx default na 60 seconds, and that timer dey run between two successive reads from Ollama, no be across the whole response. Streaming reply wey continue to produce tokens go reset the timer every time. Request wey Ollama no send anything for 60 seconds go trigger am, such as request wey use "stream": false, wey return the whole answer as one piece for the end, or request wey get long silence before the first token arrive. Client go receive 504 Gateway Time-out, and /var/log/nginx/error.log go record upstream timed out (110: Connection timed out) while reading response header from upstream. Request still dey work. nginx na e give up on am.
Reload and test both paths:
sudo nginx -t && sudo systemctl reload nginx
curl -s -o /dev/null -w '%{http_code}\n' https://llm.example.com/api/tags
curl -s -H "Authorization: Bearer YOUR_TOKEN" https://llm.example.com/api/tagsThe first one suppose print 401. The second one suppose print your model list. If the first one also return the model list, check which server and location handle the request and whether the reload succeed. map block for wrong scope go make the configuration invalid. E belong for http level, so put am inside file under /etc/nginx/conf.d/ or above server block, never inside server.
Caddy dey do the same work with basic authentication for four lines, and this fit browser client pass bearer token:
llm.example.com {
basic_auth {
apiuser PASTE_BCRYPT_HASH_HERE
}
reverse_proxy 127.0.0.1:11434
}Run caddy hash-password to produce the bcrypt hash wey e expect. One naming note: directive na basicauth before Caddy v2.8 and na basic_auth now. Caddy still accept the old spelling as deprecated alias, so config wey you copy from older guide go load, but Caddy go warn say basicauth deprecated and ask you to use basic_auth instead. Rename am when you see that warning.
Any proxy wey you choose, na one shared secret for everybody. Every client wey hold am get identical access, and to revoke am mean say you must edit config and update every caller at the same time.
Defence 3: gateway wey dey issue key for each client
Once more than one person or application dey call the model, shared token go soon finish. You no fit know which client cause the load, and you no fit block one without blocking everybody. Gateway dey sit where proxy dey sit, e dey speak the same OpenAI-compatible API, e dey issue separate key for each client, and e dey record wetin each key use. Self-hosted LiteLLM gateway na the usual answer, and e dey add per-key budgets plus request logs on top of access control.
The rule from defence 1 no change. Ollama dey bind to 127.0.0.1, na gateway be the only process wey dey talk to am, and na gateway be the only service wey get public listener. Gateway for server wey port 11434 still open to everybody na just decoration, because callers fit simply bypass am.
Firewall trap: published container port dey skip UFW
Na why exposed instances dey exist for servers wey owners configure firewall correctly.
UFW (uncomplicated firewall) dey write im rules inside INPUT chain for kernel's filter table, while INPUT dey handle packets wey target the host itself. Docker's -p flag dey write destination NAT (network address translation) rule inside PREROUTING chain for nat table, wey kernel dey evaluate before e decide where packet go. Before routing decision happen, destination don already change to container address. So packet dey get forwarded instead of delivered locally, and e pass through FORWARD instead of INPUT. UFW's INPUT rules no dey get checked, so packet dey bypass the firewall instead of passing through am.
Na why this sequence dey leave port 11434 open to the internet:
sudo ufw default deny incoming
sudo ufw enable
docker run -d -v ollama:/root/.ollama -p 11434:11434 --name ollama ollama/ollamaand sudo ufw status still dey report say firewall active with default deny. Both readings fit correct at the same time. Na exactly why people dey trust the wrong one. You fit see the rule wey cause am:
sudo iptables -t nat -L DOCKER -nThe fix na to put one address inside the publish flag:
docker rm -f ollama
docker run -d -v ollama:/root/.ollama -p 127.0.0.1:11434:11434 --name ollama ollama/ollama-p 11434:11434 no name any host address, so Docker dey publish the port on every host address, IPv4 (0.0.0.0) and IPv6 ([::]) alike. When you name 127.0.0.1, e bind the host side of the mapping to loopback, so your SSH tunnel and reverse proxy still fit reach am, but internet no fit. Docker releases older than 28.0.0 get one exception: machines for the same network segment fit reach ports published to localhost. So upgrade before you rely on this protection. Recreating the container safe for here because the models dey inside the named ollama volume, not inside the container.
Confirm say both views agree:
docker port ollama
sudo ss -tlnp | grep 11434docker port ollama suppose print 11434/tcp -> 127.0.0.1:11434. If e print 0.0.0.0:11434 or [::]:11434, you still dey exposed. Once you understand the mechanism, e apply to every container wey you ever publish: why Docker published ports dey bypass UFW explains the DOCKER-USER chain and the rules wey survive Docker restart. If you still dey build the host policy itself, the UFW rules wey a new VPS need covers the base wey this setup dey use. For Rocky or AlmaLinux, no UFW dey to configure, so the same base policy wey firewalld use na where you suppose start instead.
Process dey run as who
Linux install script dey create one dedicated account and run the service under that account:
useradd -r -s /bin/false -U -m -d /usr/share/ollama ollamaThe unit for /etc/systemd/system/ollama.service dey set User=ollama and Group=ollama. Make you leave am like that. A quick ollama serve wey you start by hand for terminal dey run as the user wey you log in with. If na root, unauthenticated API dey write files as root. Check which one e be:
ps -o user= -C ollamaThe answer suppose be ollama. Anything else mean say process wey person start by hand dey run alongside the unit, or e dey run instead of the unit. This same approach apply to every daemon wey you add later, and running services as least-privilege users handle am properly.
How to check whether Ollama API endpoint secure
No matter which option you choose, one test go confirm am, and you must run am from another machine:
curl -m 5 http://YOUR_SERVER_IP:11434/api/version
curl -m 5 http://YOUR_SERVER_IP:11434/api/tagsBoth paths suppose time out or get refused. If you build proxy, the same two paths for the proxy hostname suppose return 401 without credentials, and real JSON with credentials.
Then read the access log one time for requests wey happen while the port dey open:
journalctl -u ollama --since "-30 days" | grep GINOllama writes one line for each request and e includes the client address:
[GIN] 2026/08/12 - 14:01:10 | 200 | 103.965898ms | 127.0.0.1 | POST "/api/generate"That address dey come from Gin's ClientIP(), wey also checks X-Forwarded-For and X-Real-IP headers from trusted proxies. So, request wey pass through loopback reverse proxy fit show public client address, even while Ollama dey correctly bound to 127.0.0.1. Public address for that column no prove say person access port 11434 directly, and missing matching log lines no prove say nobody reach am. Compare the timestamps with your proxy logs and configuration, then use the outside connection test to check the current exposure. If model side of this matter still new to you, how to run Ollama on VPS explains the installation, model sizing, and memory limits wey decide wetin go actually load.
FAQ
Ollama get API key or password?
No. The server wey you run no get any authentication, and the official documentation talk say the local API no need authentication. The two things wey people call “Ollama API key” actually serve different purpose. The Ed25519 pair for /usr/share/ollama/.ollama/ proves your machine to ollama.com, so you fit push models and pull private ones. OLLAMA_API_KEY na credential wey your client sends to the hosted API for https://ollama.com/api. Your own ollama serve no use any of dem to authenticate incoming clients, so network access control or proxy in front must provide the protection.
OLLAMA_HOST=0.0.0.0 safe if I get firewall?
Na only if the firewall correctly blocks access to that listener. 0.0.0.0 means say the listener really dey exist on the public interface, and you dey trust firewall alone to keep am unreachable. Docker-published Ollama port need separate attention, because the DNAT rule wey Docker adds to the nat table dey process before packet reach the INPUT chain where UFW dey work. Because of this, packet dey forward and UFW INPUT rules no dey see am. If you bind to 127.0.0.1 or private tunnel address, the listener no go dey on public interface again. That one means firewall mistake no get anything left to expose.
How I fit check whether my Ollama port open to internet?
Run sudo ss -tlnp | grep 11434 on the server, then run curl -m 5 http://YOUR_SERVER_IP:11434/api/version from another machine. If ss show 127.0.0.1:11434 and remote curl timeout, na the two answers wey you want. If ss show 0.0.0.0:11434 or *:11434 while remote curl dey return JSON, the full API dey reachable. Curl test wey you run on the server itself no prove whether another machine fit reach am.
I fit just move the port from 11434 to any random one?
No, and e important make we explain why. Different port no go slow anything except scan for that one port. Scanners dey check the whole port range, and one request to /api/tags fit identify the service, no matter which port the request use. Moving the port also breaks every client default and makes your own setup harder to understand later. Bind to loopback instead. That one removes the listener instead of moving am.
Person reach my open Ollama. Wetin I suppose check?
First bind am to 127.0.0.1 and restart the service, so the exposure go stop before you begin investigation. Then run journalctl -u ollama --since "-30 days" | grep GIN to check client addresses, endpoints, and timestamps. Gin also dey read forwarded client-address headers, so compare those entries with your proxy logs before you treat any address as proof of direct access. Compare ollama list with the models wey you intend to get, because /api/pull no get authentication, and model wey you no pull na both disk usage and evidence. Check free space with df -h. The default access log records request metadata, but e no record model name, prompt text, or generated answer.