Pregunta

I'm running a Node/Express web server on an AWS EC2 box with Ubuntu server 12.04, and I set 4 environment variables in the .bashrc file to access my database. If I run the server as a normal user, it works fine. However, if I run node as sudo, the environment variables are undefined.

Any idea why it's not working?

¿Fue útil?

Solución

Environment variables are not passed to sudo: How to keep Environment Variables when Using SUDO

the trick is to add enviroment variables to sudoers config:

sudo visudo

add these lines

Defaults env_keep +="http_proxy"
Defaults env_keep +="https_proxy"

form ArchLinux wiki https://wiki.archlinux.org/index.php/Sudo#Environment_variables_.28Outdated.3F.29

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top