Skip to content

How to Install Home Assistant with Docker on a VPS – with HTTPS and VPN

Install Home Assistant with Docker Compose on your Linux VPS, secure access with HTTPS, and connect your smart home over a VPN → Learn more

24 November 20267 min read1 Views0 helpful

Introduction

Home Assistant is the best-known open-source platform for your smart home: Bring lights, heating, sensors, and cloud services together in one interface and build automations across all manufacturers. In this guide, you’ll install Home Assistant with Docker (the “Home Assistant Container” option) using Docker Compose on your Linux VPS, secure access with HTTPS, and connect devices in your home over a VPN.

Tip

Skip the Docker setup: Home Assistant is also available as a one-click app. The VPS automatically configures the domain and SSL certificate. See Rent a Home Assistant VPS.

When a VPS makes sense for Home Assistant

Home Assistant usually runs on a small device at home, such as a Raspberry Pi or a NAS. A VPS in a data center is a good fit if:

  • Cloud integrations are your priority, such as devices already controlled through the manufacturers’ clouds, weather data, calendars, or notifications.
  • You want your dashboards and automations to be accessible at all times, regardless of a power outage, DSL disruption, or a crash on your home Raspberry Pi.
  • You don’t want to run your own device and prefer fixed resources and backups from your hosting provider.
  • You’re bringing multiple locations together, such as your home and vacation house, both connected to the server over a VPN.

A VPS is less suitable if you mainly control radio devices directly (Zigbee, Z-Wave, Thread, Bluetooth) and need your automations to work without an internet connection. You can’t connect a USB radio stick to a server in a data center. See “Connecting devices at home” for how to integrate radio devices anyway.

Home Assistant Container or Home Assistant OS?

Home Assistant offers several installation methods. This guide uses Home Assistant Container: Home Assistant runs as a Docker container alongside your other services on the VPS.

Home Assistant ContainerHome Assistant OS
InstallationDocker container on your Linux systemDedicated operating system for the entire server
Add-ons from the add-on storeNoYes
Additional services (MQTT, Zigbee2MQTT, Node-RED)As separate containersAs add-ons
UpdatesUsing docker compose pullThrough the interface
Other services on the same serverYesNo

This guide doesn’t cover Home Assistant OS. The only thing missing from the container version is add-ons; all integrations and automations work just the same.

Requirements

  • A Linux VPS running Debian or Ubuntu with SSH access. See First access via SSH.
  • Docker and Docker Compose. See Install Docker. Check the installation with docker --version and docker compose version.
  • For HTTPS: a domain or subdomain whose A record points to your VPS’s IP address (e.g., ha.example.com).

These resources are sufficient for Home Assistant with a few dozen devices:

HardwareMinimumRecommended
CPU1 vCPU core2 vCPU cores
RAM2 GB4 GB
Storage20 GB40 GB

You’ll need more RAM and storage if you have many devices, keep a long history, or run additional services such as MQTT and Node-RED on the same server.

Prepare the firewall

Home Assistant is accessible without an account as soon as it starts: The first person to open the page can create the administrator account. So block port 8123 before starting the container. Here’s how to do that with ufw:

Code
ufw allow OpenSSH
ufw allow 80/tcp
ufw allow 443/tcp
ufw enable

This keeps port 8123 blocked from the outside. You’ll make the first connection through an SSH tunnel and access Home Assistant over HTTPS afterward. Learn more in Managing the firewall on Linux.

Install with Docker Compose

Create a directory for Home Assistant and switch to it:

Code
mkdir -p /opt/homeassistant
cd /opt/homeassistant

Create the Compose file using nano docker-compose.yml:

Code
services:
  homeassistant:
    container_name: homeassistant
    image: ghcr.io/home-assistant/home-assistant:stable
    volumes:
      - ./config:/config
      - /etc/localtime:/etc/localtime:ro
    environment:
      - TZ=Europe/Berlin
    network_mode: host
    restart: unless-stopped

Here’s what the entries mean:

  • image: the official Home Assistant image, using the stable channel.
  • ./config:/config: all settings, automations, and the database are stored in the /opt/homeassistant/config directory on your VPS.
  • network_mode: host: Home Assistant uses the server’s network directly. This lets it reach devices over the VPN later, and the server firewall applies without any Docker exceptions.
  • restart: unless-stopped: the container starts automatically after the VPS restarts.
Info

The official guide also uses privileged: true and /run/dbus. You only need these for USB and Bluetooth devices connected to the server. Leave both out on a VPS.

Start the container:

Code
docker compose up -d

Check whether it’s running with docker compose ps and view the logs with docker compose logs -f.

First access and onboarding

Because port 8123 is blocked, you’ll open the interface through an SSH tunnel the first time. Run this on your own computer:

Code
ssh -L 8123:localhost:8123 root@SERVER_IP

Replace SERVER_IP with your VPS’s IP address. Then open http://localhost:8123 in your browser. Home Assistant will guide you through setup: create an account, choose a location and time zone, and add your first integrations. Then close the tunnel.

Access over HTTPS through a reverse proxy

To access Home Assistant remotely, put a reverse proxy with an SSL certificate in front of it. For the basics, see Set up a reverse proxy with nginx and Create an SSL certificate (Let's Encrypt).

For Home Assistant, the proxy must forward WebSockets, or the interface won’t load completely. Here’s an nginx server block:

Code
server {
    listen 80;
    server_name ha.example.com;

    location / {
        proxy_pass http://127.0.0.1:8123;
        proxy_set_header Host $host;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

Then obtain the certificate with certbot --nginx -d ha.example.com. Certbot adds HTTPS and HTTP redirection to the block.

To allow Home Assistant to accept requests from the proxy, add this to /opt/homeassistant/config/configuration.yaml:

Code
http:
  use_x_forwarded_for: true
  trusted_proxies:
    - 127.0.0.1
    - ::1

Restart Home Assistant with docker compose restart. Without this entry, Home Assistant responds through the proxy with 400: Bad Request and logs a message about the reverse proxy.

Tip

Using Caddy instead of nginx is simpler: Caddy obtains the certificate itself and forwards WebSockets automatically. An entry like ha.example.com { reverse_proxy 127.0.0.1:8123 } in the Caddyfile is all you need. The http entry in configuration.yaml is still required.

Then enable two-factor authentication for your account in Home Assistant (Profile > Security). Find more tips for securing your server in Linux security tips.

Back up your data

Everything that makes up Home Assistant is stored in the /opt/homeassistant/config directory: settings, automations, dashboards, and history. Back up this directory to back up the entire installation. You have two options:

  • In Home Assistant: Go to Settings > System > Backups to create backups directly in the interface, including automatic scheduled backups.
  • On the server: Briefly stop the container and archive the directory:
Code
cd /opt/homeassistant
docker compose stop
tar -czf ha-backup-$(date +%F).tar.gz config
docker compose start

Download the backup regularly or also use your VPS backups in the web interface. To restore, put the config directory back and restart the container.

Update Home Assistant

New versions are released every month. To update:

Code
cd /opt/homeassistant
docker compose pull
docker compose up -d

Back up the config directory first and read the “Backward-incompatible changes” section in the release notes. Remove old images afterward with docker image prune.

Connect devices at home

Your VPS is in a data center, while your devices are at home. To let Home Assistant reach them, connect both networks over a VPN. The easiest option is WireGuard: the VPS acts as the VPN server, and a device at your home connects to it.

Install WireGuard on the VPS and generate a key pair:

Code
apt install wireguard
wg genkey | tee /etc/wireguard/server.key | wg pubkey > /etc/wireguard/server.pub

Create the /etc/wireguard/wg0.conf file. Set SERVER_PRIVATE_KEY to the contents of /etc/wireguard/server.key, set HOME_PUBLIC_KEY to the public key of the device at your home, and replace 192.168.178.0/24 with your home network:

Code
[Interface]
Address = 10.8.0.1/24
ListenPort = 51820
PrivateKey = SERVER_PRIVATE_KEY

[Peer]
# Router oder Gerät bei dir zu Hause
PublicKey = HOME_PUBLIC_KEY
AllowedIPs = 10.8.0.2/32, 192.168.178.0/24

Open the port and start the connection:

Code
ufw allow 51820/udp
systemctl enable --now wg-quick@wg0

On the home side, you have two options:

  • A router with WireGuard: Many routers, such as the FRITZ!Box running FRITZ!OS 7.50 or later, can establish a WireGuard connection to another network themselves. Enter the VPS’s public key, its IP address with port 51820, and the 10.8.0.0/24 network there.
  • A small device on your home network, such as a Raspberry Pi, configured as a WireGuard client with PersistentKeepalive = 25. The device forwards requests to your home network; this requires IP forwarding and a route for 10.8.0.0/24 on your router.

Once the connection is up, Home Assistant can reach your devices using their local IP addresses. Prefer OpenVPN? That works too. See Install OpenVPN.

What won’t work over the VPN

  • Automatic device discovery: mDNS, SSDP, and broadcasts don’t travel over the VPN. Devices won’t appear automatically; add them in the integration using their IP address.
  • Radio devices (Zigbee, Z-Wave, Thread, Bluetooth): These need a nearby radio coordinator. Use a network-enabled Zigbee coordinator (over LAN or Wi-Fi) that Home Assistant can reach over the VPN, or a device at home running Zigbee2MQTT that sends the data to your server over MQTT.
  • No control without an internet connection: If your home connection goes down, automations for those devices won’t work either. For an alarm system, heating, or blinds that must always work, a local installation at home is a better choice.

Conclusion

You’ve installed Home Assistant with Docker on your VPS, secured access over HTTPS, and connected your home network over a VPN. Add services such as an MQTT broker or Node-RED as additional services in the same docker-compose.yml.

Prefer to skip the Docker setup? Install Home Assistant as a one-click app. See One-click apps and Rent a Home Assistant VPS.

FAQ

Frequently asked questions

No. A VPS is a virtual machine in a data center, so you can’t connect a USB dongle to it. Instead, use a network-enabled Zigbee coordinator (over LAN or Wi-Fi) that Home Assistant can reach over the VPN, or run Zigbee2MQTT on a device at home and send the data to the server over MQTT.
No, the add-on store is only available with Home Assistant OS. However, most add-ons are available as standalone Docker images, such as Mosquitto (MQTT), Zigbee2MQTT, and Node-RED. Add them as additional services in your docker-compose.yml. Home Assistant integrations work without limitations in the Container version.
To get started, 1 vCPU core, 2 GB of RAM, and 20 GB of storage are enough. If you have many devices, keep history for a long time, or run additional services such as MQTT and Node-RED, plan for 2 vCPU cores and 4 GB of RAM. You can check usage in your VPS monitoring.

Feedback

Was this article helpful?

Your feedback helps us prioritize and improve content.

0 of 0 people found this article helpful.

Personal support

Need more help than the guide provides?

Our ZAP-Hosting support team knows your product — briefly describe your issue and we'll help you personally.

Zappy knows this guide and answers you right in the chat.