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.

This is my /etc/environment:

HELLO="hello"

Now I check that the environment is being set when connecting via ssh:

ssh foobar@my_host env

And this is the output:

SHELL=/bin/bash
SSH_CLIENT=foobar 46460 56723
USER=foobar
MAIL=/var/mail/foobar
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
PWD=/home/foobar
LANG=en_US.UTF-8
SHLVL=1
HOME=/home/foobar
LOGNAME=foobar
SSH_CONNECTION=foobar 46460 foobar 56723
_=/usr/bin/env

So: why is HELLO not being set? Is /etc/environment being parsed at all in Ubuntu? What is the recommended way to set system wide environment variables in Ubuntu?

And as bonus, it would be great if those system wide environment variables work when doing:

  • ssh (non-interactive commands)
  • ssh (interactive commands)
  • cron jobs
  • interactive login shells
  • and what-not

I mean, when I am thinking about system-wide environment variables, I really mean it!

I do not need a different method for each possible way I have to get into my machine: I just need one method, which works for all users, all commands, all login mechanisms: what could be simply described as a "system-wide setting".

Sorry for the ironic mode, but I have just been losing (again) some time with this issue.

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

Make sure you have pam_env.so added as a session module in /etc/pam.d/common-session. See also the manual of pam_env. Also make sure SSH uses PAM (UsePAM=yes in /etc/ssh/sshd_config).

share|improve this answer
    
I have added the line session required pam_env.so to /etc/pam.d/common-session, and verified that my ssh server is using PAM (UsePAM yes). It is still not working. I have even restarted the SSH server, but I had no luck. Any idea? –  jeckyll2hide Sep 5 '11 at 15:04
    
I think I got bitten badly by a quirk in my own setup: I am using ssh connection sharing, and of course no authentication is performed as long as an open connection is still there. So I had to kill all opened connections to the remote host, and reconnect from scratch. Now /etc/environment is being read as expected. –  jeckyll2hide Sep 5 '11 at 15:47
    
@gonvaled: Theoretically, the PAM session stack could be ran for every new session -- it usually doesn't depend on the auth stack in any way. It's just that OpenSSH devs chose to open a single PAM session per connection. –  grawity Sep 5 '11 at 16:54
add comment

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.