Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

2 Answers 2

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.
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:

#!/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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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