Tuesday, March 27, 2007

pam_env, /etc/environment and expansion

Rather than setting environment variables for a system in shell startup files (/etc/profile) you can use pam_env to set them (both ssh and login by default use pam_env). By default on Ubuntu this appears to be where the path is set, now to add something extra to the path I wanted to define a new value (JAVA_HOME) and then include $JAVA_HOME/bin in the path. To start with I edited /etc/environment but it seems that expansion doesn't occur in this file. However you can edit /etc/security/pam_env.conf to set the PATH and expansion does happen here. This is what I ended up adding to /etc/security/pam_env.conf : JAVA_HOME DEFAULT="/opt/jdk1.5.0_11" PATH DEFAULT="/usr/local/sbin:/usr/local/bin:/usr/sbin:\ /usr/bin:/sbin:/bin:/usr/bin/X11:/usr/games:${JAVA_HOME}/bin"

2 comments:

Alex Mestiashvili said...

Yes , this is real solution
i just put predefined PATH="/usr/local/bin:/usr/bin:/bin"
to /etc/environment
and
added
JAVA_HOME DEFAULT="/usr/java/jdk1.6.0_04"
JDK_HOME DEFAULT=${JAVA_HOME}
PATH DEFAULT=${PATH}:${JAVA_HOME}/bin

to /etc/security/pam_env.conf

tnx to Andrew G. Morgan .

Indie said...

Know this is an old post, but for user variables you should use ~/.pam_environment
The former are for system wide variables.