I'll try to answer your second, fourth, and fifth questions.
The documentation for this file is in the man page (man 5 pam_env.conf).
/etc/environment
is read after pam_env.conf
, and the man 5 pam_env.conf
says this file is read at user login.
Basically, only key=value
lines in the /etc/environment
file. The man page states that you can use the file /etc/security/pam_env.conf
to set environment variables by using other, possibly non-existent variables.
From the man page, regarding /etc/security/pam_env.conf
:
Each line starts with the variable name, there are then two possible
options for each variable DEFAULT
and OVERRIDE
. DEFAULT
allows
an administrator to set the value of the variable to some default
value, if none is supplied then the empty string is assumed. The
OVERRIDE
option tells pam_env
that it should enter in its value
(overriding the default value) if there is one to use. When OVERRIDE
is not used, ""
is assumed and no override will be done.
VARIABLE [DEFAULT=[value]] [OVERRIDE=[value]]
(Possibly non-existent) environment variables may be used in values
using the ${string}
syntax and (possibly non-existent) PAM_ITEMs as
well as HOME
and SHELL
may be used in values using the @{string}
syntax. Both the $
and @
characters can be backslash escaped to be
used as literal values values can be delimited with ""
, escaped "
not supported. Note that many environment variables that you would
like to use may not be set by the time the module is called. For
example, ${HOME}
is used below several times, but many PAM
applications don't make it available by the time you need it. The
special variables @{HOME}
and @{SHELL}
are expanded to the values
for the user from his passwd entry.
The /etc/environment file specifies the environment variables to be
set. The file must consist of simple NAME=VALUE pairs on separate
lines. The pam_env(8) module will read the file after the
pam_env.conf file.
You can also use your shell's (bash or zsh for example) configuration file or to set environment variables like that.