# Setting basic auth when running n8n with pm2

**URL:** <https://community.n8n.io/t/setting-basic-auth-when-running-n8n-with-pm2/5459>\
**Category:** Questions\
**Created:** [April 26, 2021, 5:06pm UTC](https://community.n8n.io/t/setting-basic-auth-when-running-n8n-with-pm2/5459 "2021-04-26T17:06:49Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![arkadiush](https://avatars.discourse-cdn.com/v4/letter/a/82dd89/32.png) [@arkadiush](https://community.n8n.io/u/arkadiush)\
**Post date:** [April 26, 2021, 5:06pm UTC](https://community.n8n.io/t/setting-basic-auth-when-running-n8n-with-pm2/5459/1 "2021-04-26T17:06:49Z")

</div>

Hi,  
I’m trying to setup basic auth as described in manual: [Key concepts | Docs](https://docs.n8n.io/reference/security.html)  
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?

---

<div class="post-metadata">

**Author:** ![harshil1712](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/harshil1712/32/1374_2.png) [@harshil1712](https://community.n8n.io/u/harshil1712)\
**Post date:** [April 27, 2021, 9:12am UTC](https://community.n8n.io/t/setting-basic-auth-when-running-n8n-with-pm2/5459/2 "2021-04-27T09:12:21Z")

</div>

Hey @arkadiush!

Welcome to the community 🎉

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:

- [Passing environment variables to node.js using pm2 | DigitalOcean](https://www.digitalocean.com/community/questions/passing-environment-variables-to-node-js-using-pm2)
- [PM2 - Environment Variables | Best Practices | PM2 Documentation](https://pm2.io/docs/runtime/best-practices/environment-variables/)

---

<div class="post-metadata">

**Author:** ![arkadiush](https://avatars.discourse-cdn.com/v4/letter/a/82dd89/32.png) [@arkadiush](https://community.n8n.io/u/arkadiush)\
**Post date:** [April 27, 2021, 6:12pm UTC](https://community.n8n.io/t/setting-basic-auth-when-running-n8n-with-pm2/5459/3 "2021-04-27T18:12:34Z")

</div>

Hi @harshil1712,  
I’m not sure why I didn’t read pm2 documentation carefully 🙂 lazy me 🙂 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 🙂

---

<div class="post-metadata">

**Author:** ![harshil1712](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/harshil1712/32/1374_2.png) [@harshil1712](https://community.n8n.io/u/harshil1712)\
**Post date:** [April 27, 2021, 7:09pm UTC](https://community.n8n.io/t/setting-basic-auth-when-running-n8n-with-pm2/5459/4 "2021-04-27T19:09:19Z")

</div>

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

Have fun!

---

<div class="post-metadata">

**Author:** ![Felix](https://avatars.discourse-cdn.com/v4/letter/f/aeb1de/32.png) [@Felix](https://community.n8n.io/u/Felix)\
**Post date:** [December 7, 2021, 12:18pm UTC](https://community.n8n.io/t/setting-basic-auth-when-running-n8n-with-pm2/5459/5 "2021-12-07T12:18:48Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![harshil1712](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/harshil1712/32/1374_2.png) [@harshil1712](https://community.n8n.io/u/harshil1712)\
**Post date:** [December 27, 2021, 11:53am UTC](https://community.n8n.io/t/setting-basic-auth-when-running-n8n-with-pm2/5459/6 "2021-12-27T11:53:10Z")

</div>

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](https://n8n.io/blog/how-to-set-up-n8n-via-pm2/)

---

<div class="post-metadata">

**Author:** ![Felix](https://avatars.discourse-cdn.com/v4/letter/f/aeb1de/32.png) [@Felix](https://community.n8n.io/u/Felix)\
**Post date:** [December 27, 2021, 12:06pm UTC](https://community.n8n.io/t/setting-basic-auth-when-running-n8n-with-pm2/5459/7 "2021-12-27T12:06:15Z")

</div>

Hey,  
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.
