Setting basic auth when running n8n with pm2

I’m trying to setup basic auth as described in manual: Key concepts | Docs
There are no problems running n8n directly but when I use pm2 to start it, main page is open and basic auth simply does not work. I’ve tried to pass env variables to pm2 but still no success. Are there any n8n specific configuration file where I can enable auth or another way how to use pm2 with variables that n8n will handle?

Hey @arkadiush!

Welcome to the community :tada:

I am no expert with PM2 and I have a very limited knowledge. However, a quick search on the internet and I learned that you have to combine the pm2 command when you are declare the variables (I might be wrong). Here are a few links that might help:


Hi @harshil1712,
I’m not sure why I didn’t read pm2 documentation carefully :slight_smile: lazy me :slight_smile: But anyway thank you for links.
The second one help me. What I needed to do was:
N8N_BASIC_AUTH_ACTIVE=true N8N_BASIC_AUTH_USER=user N8N_BASIC_AUTH_PASSWORD=pass pm2 restart n8n --update-env

and then
pm2 save

Now it works even after restart.
Thanks again :slight_smile:

1 Like

Awesome! I am glad that it worked out! Thanks for sharing the solution :slight_smile:

Have fun!

1 Like

I did this and now n8n won’t start the web interface and is shown at 0% CPU & 0MB RAM in pm2 monit, did i do something wrong?

Hey @Felix,

Did you find a solution?

I wrote a blog post on how to set up n8n via PM2. Maybe that can help: How to set up n8n via PM2

1 Like

I wasn’t really familiar with pm2 and thought using pm2 stop n8n would be enough to restart it, but it wasn’t, I then used pm2 kill and restarted it and now it’s working like a charm.

1 Like