Setting basic auth when running n8n with pm2

I’m trying to setup basic auth as described in manual:
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:

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

Have fun!

1 Like