Re: Environment Settings

On Mon, Jul 09, 2007 at 01:48:31PM -0600, Jialing Liang wrote:
I am using normal Unix shell (ksh).

[...] I hope to see the 'environment variables' if I
type the following command line:

ssh host1 set

That shows shell variables as well as environment variables, but doesn't
otherwise change the problem.

As I tried, the above command does not read the dotfiles

Sure it does. Or at least, it can be made to do so.

1) Set "PermitUserEnvironment yes" in sshd_config.
2) Put "ENV=$HOME/.kshrc" in ~/.ssh/environment on the server.
3) Put "barney=rubble" in ~/.kshrc on the server.
4) Put your public key in ~/.ssh/authorized_keys on the server.

Here's what I get:

# grep tester /etc/passwd
tester:x:9998:9998:User account for testing:/home/tester:/bin/ksh

# grep Environment /usr/local/etc/sshd_config
PermitUserEnvironment yes

# cat ~tester/.ssh/environment

# cat ~tester/.kshrc

imadev:~$ ssh tester@localhost set | grep barney

If you only wanted environment variables, rather than SHELL variables
(in other words, if you expected to run "ssh host1 env" instead of
"ssh host1 set"), you could bypass ~/.kshrc and simply drop the variables
directly into ~/.ssh/environment in the first place.

(In fact, I could have done that in my test, and the "barney" variable
would still have shown up in the output of "set", except that this time
it would have been an environment variable, not just an un-exported
shell variable. I just wanted to demonstrate the more difficult case.)

Relevant Pages

  • Re: zsh: which environment vars does printenv show?
    ... variable will show up in the output of printenv or not? ... that you don't understand the difference between shell variables (called ... "parameters" in the zsh man pages) and environment variables. ...
  • Re: [9fans] a bit OT, programming style question
    ... Seems Charles Forsyth's bash works very differently. ... 37 out of 49 are just environment variables (as contrasted to shell variables). ...
  • Re: csh : Existance of Environment Variable
    ... variale exists. ... $?VAR tells you whether a variable is set or not. ... Note that this applies to both environment variables and shell ... distinguish between environment variables and shell variables, ...
  • Re: Need info on the Unix export command
    ... >the unix export command. ... the export command turns a shell variable into an environment ... The difference is that shell variables are only used by that ... while environment variables are automatically inherited by ...