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.

link|improve this question
feedback

2 Answers

up vote 1 down vote accepted

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

 ~/.ssh/environment
         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.
link|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
feedback

In sshd_config, you could set e.g.

ForceCommand /usr/local/bin/setsshenv

where setsshenv looks something like this:

#!/bin/bash
export VAR1=value1
export VAR2=value2
...
exec $SSH_ORIGINAL_COMMAND

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

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.