Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Where is the most appropriate place to set environment variables for all (including non-interactive) ssh sessions, and for all users (including root)?

I believe that it may be in a script under /etc/profile.d/, but I'm not confident that making a change there won't adversely affect something else in my configuration.

share|improve this question
up vote 1 down vote accepted

From the sshd(8) man page, FILES section:

         This file is read into the environment at login (if it exists).
         It can only contain empty lines, comment lines (that start with
         ‘#’), and assignment lines of the form name=value.  The file
         should be writable only by the user; it need not be readable by
         anyone else.  Environment processing is disabled by default and
         is controlled via the PermitUserEnvironment option.
share|improve this answer
Correct me if I'm wrong, but doesn't that only set it for the one user? – Andrew Walker Nov 3 '11 at 5:38
Sure, but there are other options. See the sshd(8) man page for details. – Ignacio Vazquez-Abrams Nov 3 '11 at 12:46

In sshd_config, you could set e.g.

ForceCommand /usr/local/bin/setsshenv

where setsshenv looks something like this:

export VAR1=value1
export VAR2=value2

I'm not sure if this would run before or after users' ~/.ssh/environment scripts were read.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .