Back to Writing
AWS4 min readMarch 17, 2026

How to Set Up an Amazon EC2 Instance for Your Personal n8n Workspace

A complete step-by-step guide to installing, running, and securing n8n on an Amazon EC2 instance using Systemd and HTTPS.

Ashim Rudra Paul

Ashim Rudra Paul

Software Engineer

How to Set Up an Amazon EC2 Instance for Your Personal n8n Workspace

How to Set Up an Amazon EC2 Instance for Your Personal n8n Workspace

Prerequisites

Before we start, ensure you have:

  • An AWS account and an EC2 instance launched (Amazon Linux 2 recommended).
  • Basic familiarity with Linux commands and SSH.
  • A public IP or domain name assigned to your EC2 instance.

Step 1: Update Your System

Start by ensuring your EC2 instance is up-to-date. Connect to your instance via SSH and run:

bash
1sudo yum update -y

This command updates all installed packages, keeping your system secure and stable.

Step 2: Install Node.js and npm

n8n is built on Node.js, so install the Long-Term Support (LTS) version (Node.js 18.x at the time of writing):

bash
1curl -fsSL https://rpm.nodesource.com/setup_18.x | sudo bash -
2sudo yum install -y nodejs

Verify the installation:

bash
1node -v
2npm -v

You should see the versions of Node.js and npm displayed.

Step 3: Install n8n

With Node.js ready, install n8n globally using npm:

bash
1sudo npm install -g n8n

Confirm it is installed:

bash
1n8n --version

This should return the installed n8n version.

Step 4: Run n8n

To test n8n, start it with:

bash
1n8n

By default, n8n runs on port 5678. Open your browser and navigate to:

bash
1http://<Instance_Public_IP>:5678

Replace <Instance_Public_IP> with your EC2 instance public IP.

Configure Security Group

For external access, go to your EC2 instance’s security group in the AWS Management Console and add an inbound rule:

  • Type: Custom TCP
  • Port Range: 5678
  • Source: 0.0.0.0/0 (or restrict to your IP for better security)

Save the rule and refresh your browser.

Step 5: Set Up n8n as a Background Service

Running n8n in the foreground is fine for testing, but for production, run it as a Systemd service.

Create a Service File

Create a new service file:

bash
1sudo nano /etc/systemd/system/n8n.service

Add this content, replacing <your-user> with your Linux username (for example ec2-user on Amazon Linux):

bash
1[Unit]
2Description=n8n workflow automation tool
3After=network.target
4
5[Service]
6ExecStart=/usr/bin/n8n
7Restart=always
8User=<your-user>
9Environment=HOME=/home/<your-user>
10Environment=DATA_FOLDER=/home/<your-user>/.n8n
11
12[Install]
13WantedBy=multi-user.target

Enable and Start the Service

Reload Systemd and start n8n:

bash
1sudo systemctl daemon-reload
2sudo systemctl enable n8n
3sudo systemctl start n8n

Check status:

bash
1sudo systemctl status n8n

If it shows active (running), access n8n again at http://<Instance_Public_IP>:5678.

Step 6: Secure n8n with HTTPS

For stronger security, enable HTTPS using self-signed SSL certificates with OpenSSL.

Install OpenSSL and Generate Certificates

Install OpenSSL:

bash
1sudo yum install openssl -y

Create a directory for certificates:

bash
1sudo mkdir /etc/n8n-certs

Generate a self-signed certificate and key:

bash
1sudo openssl req -x509 -newkey rsa:4096 -keyout /etc/n8n-certs/n8n-key.pem -out /etc/n8n-certs/n8n-cert.pem -days 365 -nodes

Verify files:

bash
1ls /etc/n8n-certs
2ls -l /etc/n8n-certs

Set ownership to EC2 user:

bash
1sudo chown ec2-user:ec2-user /etc/n8n-certs/n8n-key.pem
2sudo chown ec2-user:ec2-user /etc/n8n-certs/n8n-cert.pem

Step 7: Update the Service for HTTPS

Modify the service file:

bash
1sudo nano /etc/systemd/system/n8n.service

Replace with:

bash
1[Unit]
2Description=n8n service
3After=network.target
4
5[Service]
6Type=simple
7User=ec2-user
8ExecStart=/usr/bin/n8n
9Environment=N8N_HOST=<your_public_ip_address>
10Environment=N8N_PORT=5678
11Environment=N8N_PROTOCOL=https
12Environment=N8N_BASIC_AUTH_ACTIVE=true
13Environment=N8N_BASIC_AUTH_USER=<your_username>
14Environment=N8N_BASIC_AUTH_PASSWORD=<your_password>
15Environment=N8N_SSL_KEY=/etc/n8n-certs/n8n-key.pem
16Environment=N8N_SSL_CERT=/etc/n8n-certs/n8n-cert.pem
17Restart=always
18
19[Install]
20WantedBy=multi-user.target

Replace:

  • <your_public_ip_address> with your EC2 public IP
  • <your_username> with your preferred username
  • <your_password> with a strong password

Restart the Service

Apply changes:

bash
1sudo systemctl daemon-reload
2sudo systemctl restart n8n
3sudo systemctl status n8n

Now access n8n securely at:

bash
1https://<Instance_Public_IP>:5678

Final Notes

Your personal n8n workspace is now running on EC2 with background process management and HTTPS enabled. For production-ready security, consider using a domain name with a trusted TLS certificate (for example Let’s Encrypt) and tighter security group rules.