Ollama on Ubuntu 26.04 LTS on Azure User Guide
Overview
This guide covers the deployment and use of Ollama on Ubuntu 26.04 LTS on Azure using the cloudimg Azure Marketplace image. Ollama is an open source runtime that downloads and serves large language models such as Llama, Gemma, Mistral, Qwen and Phi behind one REST API that is also compatible with OpenAI's chat completions (/v1/chat/completions).
The image installs Ollama 0.40.19 from Ollama's own release (ollama-linux-amd64.tar.zst, checked against the SHA-256 digest published with the release) to /usr/local/bin/ollama and /usr/local/lib/ollama, and runs it under systemd as the unprivileged ollama user. Ollama has no authentication of its own, so the server listens on loopback only (127.0.0.1:11434) and nginx is the only network facing service: it serves HTTPS on port 443 and asks for HTTP Basic auth on every request except the open health endpoints.
What is included:
-
Ollama 0.40.19 as
ollama.service, with theollamacommand line, and the model store at/var/lib/ollama/models -
The Ollama server on
127.0.0.1:11434only, never reachable from the network directly -
nginx on port 443 with a self signed TLS certificate made for your VM, and HTTP Basic auth (user
admin) on the model API;GET /api/versionand/healthzstay open for health probes; port 80 redirects to HTTPS -
A per VM password and certificate generated on first boot and written to
/root/ollama-credentials.txt(root only): no default or shared login -
No model in the image: you pull the models you want, each under its own licence
-
Models run on the CPU
-
Ubuntu 26.04 LTS with unattended security upgrades left on
-
cloudimg's support team on hand 24 hours a day by email (support@cloudimg.co.uk), with a guaranteed response within 24 hours
Prerequisites
-
An active Azure subscription and an SSH public key
-
A virtual network and subnet in your target region (the Portal creates them for you if needed)
-
Network Security Group rules allowing TCP 22 and TCP 443 from your own network only
Recommended virtual machine size: Standard_B2ms (2 vCPU, 8 GB RAM) for small models of up to about 3 billion parameters. A model needs roughly its download size in memory plus 1 to 2 GB; use Standard_D4s_v5 (16 GB) or Standard_D8s_v5 (32 GB) for 7B to 14B models and faster answers. More vCPUs give more tokens per second.
Step 1: Deploy the virtual machine
Option A: Azure Portal
Search for Ollama on Ubuntu 26.04 LTS in the Azure Marketplace, select the cloudimg offer and click Create. Choose your resource group, region and size, set the administrator username and your SSH public key, and allow inbound SSH (22) and HTTPS (443) from your own address. Review and create.
Option B: Azure CLI
Accept the Marketplace terms once per subscription, then create the VM and open HTTPS to your own network:
RG="ollama-prod"; LOCATION="eastus"; VM_NAME="ollama-host"
IMAGE_URN="cloudimg1647283583153:ollama-ubuntu-26-04:default:latest"
az group create --name "$RG" --location "$LOCATION"
az vm image terms accept --urn "$IMAGE_URN"
az vm create \
--resource-group "$RG" --name "$VM_NAME" \
--image "$IMAGE_URN" \
--size Standard_B2ms \
--admin-username azureuser \
--ssh-key-values ~/.ssh/id_rsa.pub \
--public-ip-sku Standard
az vm open-port --resource-group "$RG" --name "$VM_NAME" --port 443 --priority 1010
az vm open-port opens 443 to any address; narrow the rule's source to your own network in the Network Security Group afterwards.
Step 2: Connect over SSH
PUBLIC_IP=$(az vm show -d --resource-group "$RG" --name "$VM_NAME" --query publicIps -o tsv)
ssh azureuser@"$PUBLIC_IP"
Step 3: Read your credentials
On first boot the image makes the TLS certificate and the admin password for this VM, starts Ollama and nginx, checks that anonymous requests are refused, and writes everything to a root only file. This completes within a minute of the VM starting. Read it:
sudo cat /root/ollama-credentials.txt
# Ollama - generated on first boot. These credentials are unique to this VM. Store them safely.
#
OLLAMA_HOST=<your-vm-public-ip>
OLLAMA_URL=https://<your-vm-public-ip>/
OLLAMA_USERNAME=admin
OLLAMA_PASSWORD=<password>
#
# The Ollama API is served over HTTPS on port 443 (nginx, TLS + HTTP Basic auth) and proxied to the Ollama
# server on loopback 127.0.0.1:11434. Every request except GET /api/version and /healthz needs the
# credential above.
#
# Self-signed certificate: /etc/nginx/tls/ollama.crt (copy it to your client, or use curl --cacert).
# Health (open): curl --cacert ollama.crt https://<your-vm-public-ip>/api/version
# List models: curl -u admin:<password> --cacert ollama.crt https://<your-vm-public-ip>/api/tags
# Pull a model: curl -u admin:<password> --cacert ollama.crt https://<your-vm-public-ip>/api/pull -d '{"model":"llama3.2:1b"}'
# OpenAI clients: base_url https://<your-vm-public-ip>/v1 with HTTP Basic auth admin / the password above
#
# No model ships in the image: pull the ones you want (each carries its own licence).
# On the VM: ollama pull <model>, ollama run <model>, ollama list. Models live in /var/lib/ollama/models.
# This image runs models on the CPU.
#
# To change the address this file, the login banner and the certificate use (a new public IP or your DNS
# name): sudo cloudimg-set-public-address <public-ip-or-dns-name>. It re-mints the self-signed certificate
# (one you installed yourself is left alone) and restarts nginx.
Store the password somewhere safe: it is unique to this VM.
If the file shows <your-vm-public-ip> (Azure told the VM no public IP), set the address it, the login message and the certificate should use, with your public IP or DNS name: sudo cloudimg-set-public-address <public-ip-or-dns-name>. It re-mints the certificate for that address and restarts nginx; the password does not change.
Step 4: Confirm Ollama and nginx are running
ollama.service and nginx.service are active and enabled. The Ollama server listens on loopback only; nginx listens on 80 and 443:
systemctl is-active ollama.service nginx.service
systemctl is-enabled ollama.service nginx.service
ollama --version
sudo ss -Hltn '( sport = :11434 or sport = :443 or sport = :80 )'

Step 5: HTTPS and HTTP Basic auth
The model API needs the admin password; the version endpoint stays open for health probes. Load the password into a variable from the credentials file, then compare an anonymous request, a wrong password and the right one. The certificate is root only, so the curl calls that read it use sudo:
API_AUTH="admin:$(sudo sed -n 's/^OLLAMA_PASSWORD=//p' /root/ollama-credentials.txt)"
CA=/etc/nginx/tls/ollama.crt
sudo curl -s --cacert "$CA" https://127.0.0.1/api/version; echo
sudo curl -s -o /dev/null -w 'anonymous /api/tags -> %{http_code}\n' --cacert "$CA" \
https://127.0.0.1/api/tags
sudo curl -s -o /dev/null -w 'wrong login /api/tags -> %{http_code}\n' -u admin:wrong --cacert "$CA" \
https://127.0.0.1/api/tags
sudo curl -s -o /dev/null -w 'admin login /api/tags -> %{http_code}\n' -u "$API_AUTH" --cacert "$CA" \
https://127.0.0.1/api/tags

Step 6: Pull a model and run it
No model ships in the image, so the first step is to pull one. This example uses Qwen 2.5 0.5B (Apache 2.0, about 400 MB), which answers in a few seconds on two vCPUs; any model from the Ollama library works the same way. On the VM, the ollama command talks to the local server directly:
ollama pull qwen2.5:0.5b
ollama list
ollama run qwen2.5:0.5b "In one sentence, what is a large language model?"
The same through the HTTPS API, as your applications call it:
API_AUTH="admin:$(sudo sed -n 's/^OLLAMA_PASSWORD=//p' /root/ollama-credentials.txt)"
sudo curl -s -u "$API_AUTH" --cacert /etc/nginx/tls/ollama.crt https://127.0.0.1/api/generate \
-d '{"model":"qwen2.5:0.5b","prompt":"Name three primary colours.","stream":false}' | jq -r '.response'
ollama ps

ollama ps shows the loaded model and 100% CPU: this image runs models on the CPU.
Step 7: The OpenAI compatible API
Ollama answers OpenAI style requests on /v1 (chat completions, completions, embeddings and the model list), so OpenAI SDKs, LangChain, LlamaIndex and other clients work by changing the base URL:
API_AUTH="admin:$(sudo sed -n 's/^OLLAMA_PASSWORD=//p' /root/ollama-credentials.txt)"
sudo curl -s -u "$API_AUTH" --cacert /etc/nginx/tls/ollama.crt https://127.0.0.1/v1/chat/completions \
-H 'Content-Type: application/json' \
-d '{"model":"qwen2.5:0.5b","messages":[{"role":"user","content":"Say hello in French."}]}' \
| jq '{model, answer: .choices[0].message.content}'
sudo curl -s -u "$API_AUTH" --cacert /etc/nginx/tls/ollama.crt https://127.0.0.1/v1/models \
| jq -c '.data[] | {id, object, owned_by}'

Step 8: Call the API from your computer
Copy the VM's certificate to your computer so clients can trust it, then call the API on the public address:
ssh azureuser@"$PUBLIC_IP" 'sudo cat /etc/nginx/tls/ollama.crt' > ollama.crt
curl --cacert ollama.crt https://$PUBLIC_IP/api/version
curl -u admin:<password> --cacert ollama.crt https://$PUBLIC_IP/api/tags
From Python with the OpenAI SDK, pass the Basic auth through an httpx client:
import httpx
from openai import OpenAI
client = OpenAI(
base_url="https://<public-ip>/v1",
api_key="unused",
http_client=httpx.Client(auth=("admin", "<password>"), verify="ollama.crt"),
)
reply = client.chat.completions.create(
model="qwen2.5:0.5b",
messages=[{"role": "user", "content": "Say hello in French."}],
)
print(reply.choices[0].message.content)
If curl says SSL: no alternative certificate subject name matches, the certificate was made for another address: run sudo cloudimg-set-public-address <public-ip-or-dns-name> on the VM (Step 3) and copy the certificate again.
Step 9: Manage models
ollama list
ollama show qwen2.5:0.5b
ollama rm qwen2.5:0.5b
df -h /var/lib/ollama
Models are stored in /var/lib/ollama/models on the OS disk. Large models fill a 30 GB disk quickly: resize the OS disk in the Azure portal, or attach a data disk, mount it (for example at /data), give it to the ollama user and point OLLAMA_MODELS in /etc/systemd/system/ollama.service.d/cloudimg.conf at it, then sudo systemctl daemon-reload && sudo systemctl restart ollama.
Step 10: Use your own domain and certificate
For production, point a DNS name at the VM, set it as the VM's address with sudo cloudimg-set-public-address ollama.example.com, then replace /etc/nginx/tls/ollama.crt and /etc/nginx/tls/ollama.key with a certificate from your CA (for example Let's Encrypt) and run sudo nginx -t && sudo systemctl reload nginx. A certificate you install yourself is never replaced by cloudimg-set-public-address.
To change the API password, write a new bcrypt entry and update your note of it:
sudo htpasswd -B /etc/nginx/.ollama.htpasswd admin
Step 11: Upgrade Ollama
Ollama is not installed from an apt repository, so unattended upgrades patch Ubuntu but not Ollama. To move to a newer release, download it from Ollama's releases, check its SHA-256 digest against the one shown on the release page, unpack it over /usr/local and restart the service. Remove the cuda_* directories if you keep the CPU only layout this image ships:
VER=<version>
curl -fL -o /tmp/ollama.tar.zst https://github.com/ollama/ollama/releases/download/v$VER/ollama-linux-amd64.tar.zst
sha256sum /tmp/ollama.tar.zst
sudo systemctl stop ollama
sudo rm -rf /usr/local/lib/ollama
zstd -dc /tmp/ollama.tar.zst | sudo tar -xf - -C /usr/local
sudo rm -rf /usr/local/lib/ollama/cuda_*
sudo systemctl start ollama
ollama --version
Your models and settings are kept.
Server components
| Component | Version |
|---|---|
| Ollama | 0.40.19 (CPU backends: llama.cpp / ggml) |
| nginx | 1.28.3 (Ubuntu) |
| OpenSSL | 3.5.5 |
| Operating system | Ubuntu 26.04.1 LTS, Azure tuned kernel 7.0 |
| Models | None included: pull the ones you want |
Filesystem layout
| Path | What it holds |
|---|---|
/usr/local/bin/ollama |
The Ollama server and command line |
/usr/local/lib/ollama |
Ollama's CPU backends (llama.cpp / ggml) |
/var/lib/ollama/models |
Pulled models |
/etc/systemd/system/ollama.service.d/cloudimg.conf |
Listen address (OLLAMA_HOST) and model store (OLLAMA_MODELS) |
/etc/nginx/sites-available/cloudimg-ollama |
The nginx HTTPS proxy and auth |
/etc/nginx/.ollama.htpasswd |
The admin password (bcrypt) |
/etc/nginx/tls/ollama.crt, ollama.key |
The VM's TLS certificate and key |
/root/ollama-credentials.txt |
The first boot credentials (root only) |
/mnt |
The Azure temporary disk: its contents are lost when the VM is deallocated, so never keep models there |
Managing the service
sudo systemctl status ollama.service nginx.service --no-pager --lines=0
sudo journalctl -u ollama.service -n 20 --no-pager
Restart Ollama with sudo systemctl restart ollama and nginx with sudo systemctl restart nginx. Ollama settings such as OLLAMA_KEEP_ALIVE, OLLAMA_NUM_PARALLEL or OLLAMA_CONTEXT_LENGTH go in /etc/systemd/system/ollama.service.d/cloudimg.conf as further Environment= lines, followed by sudo systemctl daemon-reload && sudo systemctl restart ollama. Keep OLLAMA_HOST on 127.0.0.1:11434.
Troubleshooting
-
401 Unauthorized: the request has no credential or the wrong one. Use the useradminand the password in/root/ollama-credentials.txt. -
502 Bad Gateway: nginx cannot reach Ollama. Checksystemctl status ollamaandsudo journalctl -u ollama -n 50. -
model "..." not found: pull the model first (ollama pull <model>);ollama listshows what is on the VM. -
Answers are slow or the model will not load: the model is too large for the VM's memory or vCPUs. Use a smaller or more quantised model, or resize the VM.
-
SSL: no alternative certificate subject name matches: the certificate does not name the address you call; see Step 8. -
First boot details:
sudo journalctl -u ollama-firstboot.serviceand/var/log/cloudimg-firstboot.log.
Security recommendations
-
Restrict the NSG. Allow 22 and 443 only from the networks that need them.
-
Keep Ollama on loopback. Do not set
OLLAMA_HOSTto0.0.0.0: Ollama itself has no authentication, and nginx is what asks for the password. Anyone with a shell on the VM can use the local API on127.0.0.1:11434, so give shell access only to trusted administrators. -
Rotate the password if it is shared beyond the people who need it (Step 10), and use a CA signed certificate in production.
-
Check model licences. Each model carries its own licence and terms of use: read them before use in production.
-
Keep Ubuntu current. Unattended security upgrades stay on; upgrade Ollama itself as in Step 11.
Support and licensing
Ollama is open source software under the MIT License. The image ships Ollama's CPU backends (llama.cpp and ggml, MIT) and not the NVIDIA CUDA libraries Ollama's release also carries. No model is included: each model you pull is licensed by its own authors. cloudimg provides the packaging, the first boot setup, the image maintenance and support. cloudimg's support team is on hand 24 hours a day by email (support@cloudimg.co.uk), with a guaranteed response within 24 hours.
Ubuntu is a registered trademark of Canonical Ltd. cloudimg is not affiliated with, endorsed by or sponsored by Ollama or Canonical.
Deploy on Azure
Find Ollama on Ubuntu 26.04 LTS on the Azure Marketplace, published by cloudimg, and deploy it from the Portal or the Azure CLI as shown above.
Need help?
Email support@cloudimg.co.uk for deployment help, configuration questions or licensing enquiries.