🚀Easiest Way to Run n8n on Azure Ubuntu VM – Portal + Run Command
This guide shows you how to launch a fully functional n8n instance on an Azure Ubuntu VM entirely through the Azure Portal. No local SSH or CLI needed – everything is done with clicks and the Run Command feature. It includes steps to create the VM and configure network access for port 5678.
1️⃣ Create an Ubuntu VM in Azure Portal
Follow these steps to create your Ubuntu VM:
- Sign in to Azure Portal portal.azure.com and ensure you’re in the correct subscription.
- Search for "Virtual Machines" in the top search bar and click to open the service.
- Click "+ Create" > "Virtual Machine" to start the creation wizard.

- Basics tab:
- Subscription: Select your subscription.
- Resource group: Create a new one (e.g., "n8n-rg") or use an existing one.
- Virtual machine name: Enter a name (e.g., "n8n-vm").
- Region: Choose a region close to you (e.g., "West Europe").
- Image: Select "Ubuntu Server 22.04 LTS".
- Size: Choose a size (e.g., "Standard B2s" for basic use).
- Authentication type: Select "Password" and set a username + strong password.
- Review + create: Validate settings and click "Create". Wait 5–10 minutes.
Tip: Note the public IP address displayed after deployment in the VM overview.
2️⃣ Configure Inbound Rule for Port 5678
To allow n8n traffic on port 5678, configure the Network Security Group (NSG):
- Go to the VM in Azure Portal and click on Networking.
- Click the NSG name (e.g., "n8n-vm-nsg").
- Click "Inbound security rules" > "+ Add".

3️⃣ Run Command to Deploy n8n
After VM creation and firewall setup, use Run Command in the Azure Portal:
- Open your VM.
- Click Run Command under "Operations".
- Select RunShellScript and paste the script below.

#!/bin/bash
# ==========================================
# Install Docker and start n8n on Azure VM
# ==========================================
# Update package lists
sudo apt-get update -y
# Install required packages
sudo apt-get install -y ca-certificates curl gnupg lsb-release
# Install Docker
mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update -y
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
# Start and enable Docker
sudo systemctl start docker
sudo systemctl enable docker
# ==========================================
# Run n8n container
# ==========================================
# Get dynamic public IP
PUBLIC_IP=$(curl -s ifconfig.me)
if [ -z "$PUBLIC_IP" ]; then
echo "Could not fetch public IP address. Using 74.241.244.217 as fallback."
PUBLIC_IP="74.241.244.217"
fi
# Stop old container if it exists
sudo docker stop n8n || true
sudo docker rm n8n || true
# Start new container with dynamic IP
sudo docker run -d \
--name n8n \
--restart unless-stopped \
-p 5678:5678 \
-e N8N_BASIC_AUTH_ACTIVE=true \
-e N8N_BASIC_AUTH_USER=admin \
-e N8N_BASIC_AUTH_PASSWORD=secret_password \
-e N8N_HOST=$PUBLIC_IP \
-e N8N_PORT=5678 \
-e N8N_PROTOCOL=http \
-e N8N_SECURE_COOKIE=false \
-e N8N_WEBSOCKET_ENDPOINT=/websocket \
-e TZ=Europe/Stockholm \
-v n8n_data:/home/node/.n8n \
n8nio/n8n:latest
# Show container status and logs
sudo docker ps
echo "-------------------"
sudo docker logs n8n
echo "n8n is now running at http://$PUBLIC_IP:5678"
echo "Login with username 'admin' and password 'secret_password'"
echo "Note: You may encounter 'Error connecting to n8n' due to WebSocket issues over HTTP. A domain with HTTPS is recommended for full functionality."
5️⃣ Test Your n8n Instance
- Check the Public IP address in VM overview.
- Go to
http://<Public-IP>:5678
in your browser. - Log in with:
Username: admin
Password: secret_password

✅ You now have a fully functional n8n server running on your Azure VM, provisioned entirely via the Azure Portal – no local scripts or CLI required.
Visual Guide for Troubleshooting
These images show key steps to check before troubleshooting:


6️⃣ Troubleshooting: n8n Won’t Open
If you encounter issues like "Hmmm… can't reach this page" or "ERR_CONNECTION_REFUSED" when accessing http://<Public-IP>:5678
, follow these steps:
- Check VM Status:
- Ensure the VM is running in Azure Portal. If stopped, click Start and wait 1-2 minutes.
- Verify Public IP:
- Confirm the correct public IP in the VM overview. If it changed after a restart, update the URL (e.g., from
74.241.244.217
to the new IP).
- Confirm the correct public IP in the VM overview. If it changed after a restart, update the URL (e.g., from
- Check Container Status:
- Use Run Command to run sudo docker ps. If no container named "n8n" is listed with "Up" status and port 5678, re-run the script from Step 3️⃣.
- Review Logs:
- Run sudo docker logs n8n via Run Command. Look for errors (e.g., port conflicts or startup failures). Share the output if unsure.
- Validate NSG Rule:
- Go to VM > Networking > NSG > "Inbound security rules". Ensure "Allow-n8n-5678" allows traffic on port 5678 from "Any" (or your IP). If missing, add it as in Step 2️⃣.
- Test Locally:
- Run curl http://localhost:5678 via Run Command. If it works, the issue is outside the VM (e.g., NSG or your network).
- Re-run Script:
- If all else fails, re-run the script from Step 3️⃣ to recreate the container.
sudo docker ps
sudo docker logs n8n
curl http://localhost:5678
Tip: If problems persist, note the error message and check your internet connection or Azure Portal for VM/network issues.
Kommentarer
Skicka en kommentar