5

I have the following line my /etc/environment file:

BROKER_URL=tcp://xxx.30.8.163:61616

I run this and get:

$ set|grep BROKER_URL
BROKER_URL=tcp://xxx.30.8.163:61616

Then, I run:

$ sudo bash
# set|grep BROKER_URL
# 

This is supposed to be a system wide environment variable. Why doesn't it show up in my sudo shell?

Thom
  • 7,855

1 Answers1

5

/etc/environment is a file used by PAM, meaning it is processed by a log in, which sudo bash does not do, and (from man sudoers):

Command environment

Since environment variables can influence program behavior, sudoers provides a means to restrict which variables from the user's environment are inherited by the command to be run. There are two distinct ways sudoers can deal with environment variables.

By default, the env_reset option is enabled. This causes commands to be executed with a new, minimal environment. On AIX (and Linux systems without PAM), the environment is initialized with the contents of the /etc/environment file.

Note that most GNU/linux systems do use PAM. You could try to get around this by using sudo -i, to use a login shell. However, this likely will still not work as "login shell" refers to how bash invokes itself, which does not include sourcing /etc/environment, and you are not actually logging in via PAM.

Your best bet is probably to configure sudo to do what you want.

goldilocks
  • 87,661
  • 30
  • 204
  • 262