Create environment with access to n8n self host

Hello,
I have installed n8n in my self host, but n8n can be accessed by anyone and change my workflows and see my data.
Is there some way to close this access?

Thank you.

Welcome to the community @Anderson_Rogerio_Gab

You might want to set the env variables N8N_BASIC_AUTH_USER and N8N_BASIC_AUTH_PASSWORD

Thank you @RicardoE105
I’m using npm already did the command:

export N8N_BASIC_AUTH_ACTIVE=true
export N8N_BASIC_AUTH_USER=user1
export N8N_BASIC_AUTH_PASSWORD=123456

It should works, all right?
However anyone can be access, keeping without protected.
Is there another way to set this env variables?

@Anderson_Rogerio_Gab did it prompt you for the credentials? How did you install n8n?

I installed with ‘npm install n8n’ without -g because I’m hosting on Cloudways and it not possible install globally.
So I run n8n with $(npm bin)/n8n start.
But I change variable of database to MariaDb and it works very well.
And when I change the variables to basic auth it not works.

Did you set the environment variables in the same terminal/environment n8n got started in? If you did set it later, did you restart n8n?

Honestly still have a hard time understanding how you start/run n8n. Do you use something like pm2? If so did you check out this blog-post?

My money is on the environment variables not being set in the environment or it isn’t being picked up properly on launch.

Can you share the full set of commands you are running maybe someone can give it a quick test locally to see what happens.

Works!!!
I was setting env wrong! :stuck_out_tongue_winking_eye:
I’m using PM2, so I have a file with command shell to run n8n start, I added the variables before!
Thank you very much guys!

Look my file n8n.sh →

export N8N_HOST=<URL_HERE.com.br>
export N8N_PROTOCOL=https
export N8N_BASIC_AUTH_ACTIVE=true
export N8N_BASIC_AUTH_USER=
export N8N_BASIC_AUTH_PASSWORD=********
export DB_TYPE=mariadb
export DB_MYSQLDB_DATABASE=
export DB_MYSQLDB_HOST=localhost
export DB_MYSQLDB_PORT=3306
export DB_MYSQLDB_USER=<USER_DB>
export DB_MYSQLDB_PASSWORD=<PASSWORD_DB>
$(npm bin)/n8n start

2 Likes

Glad to hear. Have fun!

:+1: nice to hear you are up and running